提交 1d894f8a 编写于 作者: M Minwe

reformat js code

上级 0e15dd1d
{
"preset": "google",
"disallowEmptyBlocks": true,
"disallowKeywords": ["with"],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineStrings": true,
"disallowQuotedKeysInObjects": "allButReserved",
"disallowSpaceAfterPrefixUnaryOperators": [
"++",
"--",
"+",
"-",
"~",
"!"
],
"disallowSpaceBeforeBinaryOperators": [","],
"disallowSpaceBeforePostfixUnaryOperators": [
"++",
"--"
],
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,
"requireCamelCaseOrUpperCaseIdentifiers": true,
"requireCapitalizedConstructors": true,
"requireCommaBeforeLineBreak": true,
"requireDotNotation": true,
"requireLineFeedAtFileEnd": true,
"requireSpaceAfterBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
"<",
">=",
"<="
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch",
"case",
"void"
],
"requireSpaceAfterLineComment": true,
"requireSpaceBeforeBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
"<",
">=",
"<="
],
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInConditionalExpression": true,
"requireSpacesInFunctionDeclaration": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"validateIndentation": 2,
"validateLineBreaks": "LF",
"validateQuoteMarks": "'",
"excludeFiles": ["node_modules/**"]
}
\ No newline at end of file
......@@ -3,13 +3,18 @@
"bitwise": true,
"camelcase": true,
"curly": true,
"expr": true,
"immed": true,
"indent": 4,
"indent": 2,
"maxlen": 80,
"newcap": true,
"noarg": true,
"quotmark": "single",
"undef": true,
"unused": "vars",
"strict": true
"strict": true,
"globals": {
"define": true,
"module": true
}
}
此差异已折叠。
此差异已折叠。
define(function(require, exports, module) {
'use strict';
require('core');
var $ = window.Zepto,
UI = $.AMUI;
/**
* @via https://github.com/Minwe/bootstrap/blob/master/js/alert.js
* @copyright Copyright 2013 Twitter, Inc.
* @license Apache 2.0
*/
// Alert Class
// NOTE: removeElement option is unavailable now
var Alert = function(element, options) {
this.options = $.extend({}, Alert.DEFAULTS, options);
this.$element = $(element);
this.$element.
addClass('am-fade am-in').
on('click.alert.amui', '.am-close', $.proxy(this.close, this));
};
Alert.DEFAULTS = {
removeElement: true
};
Alert.prototype.close = function() {
var $this = $(this),
$target = $this.hasClass('am-alert') ?
$this :
$this.parent('.am-alert');
$target.trigger('close:alert:amui');
$target.removeClass('am-in');
function processAlert() {
$target.off().trigger('closed:alert:amui').remove();
}
UI.support.transition && $target.hasClass('am-fade') ?
$target.
one(UI.support.transition.end, processAlert).
emulateTransitionEnd(200) : processAlert();
};
// Alert Plugin
$.fn.alert = function(option) {
return this.each(function() {
var $this = $(this),
data = $this.data('amui.alert'),
options = typeof option == 'object' && option;
if (!data) {
$this.data('amui.alert', (data = new Alert(this, options || {})));
}
if (typeof option == 'string') {
data[option].call($this);
}
});
};
'use strict';
require('core');
var $ = window.Zepto,
UI = $.AMUI;
/**
* @via https://github.com/Minwe/bootstrap/blob/master/js/alert.js
* @copyright Copyright 2013 Twitter, Inc.
* @license Apache 2.0
*/
// Alert Class
// NOTE: removeElement option is unavailable now
var Alert = function(element, options) {
this.options = $.extend({}, Alert.DEFAULTS, options);
this.$element = $(element);
this.$element.addClass('am-fade am-in').on('click.alert.amui', '.am-close', $.proxy(this.close, this));
};
Alert.DEFAULTS = {
removeElement: true
};
Alert.prototype.close = function() {
var $this = $(this),
$target = $this.hasClass('am-alert') ? $this : $this.parent('.am-alert');
$target.trigger('close:alert:amui');
$target.removeClass('am-in');
function processAlert() {
$target.off().trigger('closed:alert:amui').remove();
}
UI.support.transition && $target.hasClass('am-fade') ?
$target
.one(UI.support.transition.end, processAlert)
.emulateTransitionEnd(200) : processAlert();
};
UI.alert = Alert;
// Alert Plugin
$.fn.alert = function(option) {
return this.each(function() {
var $this = $(this),
data = $this.data('amui.alert'),
options = typeof option == 'object' && option;
if (!data) {
$this.data('amui.alert', (data = new Alert(this, options || {})));
}
if (typeof option == 'string') {
data[option].call($this);
}
});
};
// Init code
$(document).on('click.alert.amui', '[data-am-alert]', function(e) {
var $target = $(e.target);
$(this).addClass('am-fade am-in');
$target.is('.am-close') && $(this).alert('close');
});
// Init code
$(document).on('click.alert.amui', '[data-am-alert]', function(e){
var $target = $(e.target);
$(this).addClass('am-fade am-in');
$target.is('.am-close') && $(this).alert('close');
});
UI.alert = Alert;
module.exports = Alert;
module.exports = Alert;
});
define(function(require, exports, module) {
'use strict';
require('core');
var $ = window.Zepto,
UI = $.AMUI;
/**
* @via https://github.com/twbs/bootstrap/blob/master/js/button.js
* @copyright (c) 2011-2014 Twitter, Inc
* @license The MIT License
*/
var Button = function(element, options) {
this.$element = $(element);
this.options = $.extend({}, Button.DEFAULTS, options);
this.isLoading = false;
this.hasSpinner = false;
};
Button.DEFAULTS = {
loadingText: 'loading...',
className: {
loading: 'am-btn-loading',
disabled: 'am-disabled'
},
spinner: undefined
};
Button.prototype.setState = function(state) {
var disabled = 'disabled',
$element = this.$element,
options = this.options,
val = $element.is('input') ? 'val' : 'html',
loadingClassName = options.className.disabled +
' ' + options.className.loading;
state = state + 'Text';
if (!options.resetText) {
options.resetText = $element[val]();
}
'use strict';
require('core');
// add spinner for element with html()
if (UI.support.animation && options.spinner &&
val === 'html' && !this.hasSpinner) {
options.loadingText = '<span class="am-icon-' +
options.spinner +
' am-icon-spin"></span>' + options.loadingText;
var $ = window.Zepto,
UI = $.AMUI;
this.hasSpinner = true;
}
/**
* @via https://github.com/twbs/bootstrap/blob/master/js/button.js
* @copyright (c) 2011-2014 Twitter, Inc
* @license The MIT License
*/
$element[val](options[state]);
var Button = function(element, options) {
this.$element = $(element);
this.options = $.extend({}, Button.DEFAULTS, options);
// push to event loop to allow forms to submit
setTimeout($.proxy(function() {
if (state == 'loadingText') {
$element.addClass(loadingClassName).attr(disabled, disabled);
this.isLoading = true;
} else if (this.isLoading) {
$element.removeClass(loadingClassName).removeAttr(disabled);
this.isLoading = false;
this.hasSpinner = false;
};
Button.DEFAULTS = {
loadingText: 'loading...',
className: {
loading: 'am-btn-loading',
disabled: 'am-disabled'
},
spinner: undefined
};
Button.prototype.setState = function(state) {
var disabled = 'disabled',
$element = this.$element,
options = this.options,
val = $element.is('input') ? 'val' : 'html',
loadingClassName = options.className.disabled + ' ' + options.className.loading;
state = state + 'Text';
if (!options.resetText) {
options.resetText = $element[val]();
}
// add spinner for element with html()
if (UI.support.animation && options.spinner && val === 'html' && !this.hasSpinner) {
options.loadingText = '<span class="am-icon-' + options.spinner +' am-icon-spin"></span>' + options.loadingText;
this.hasSpinner = true;
}
$element[val](options[state]);
// push to event loop to allow forms to submit
setTimeout($.proxy(function() {
if (state == 'loadingText') {
$element.addClass(loadingClassName).attr(disabled, disabled);
this.isLoading = true;
} else if (this.isLoading) {
$element.removeClass(loadingClassName).removeAttr(disabled);
this.isLoading = false;
}
}, this), 0);
};
Button.prototype.toggle = function() {
var changed = true,
$element = this.$element,
$parent = this.$element.parent('.am-btn-group');
if ($parent.length) {
var $input = this.$element.find('input');
if ($input.prop('type') == 'radio') {
if ($input.prop('checked') && $element.hasClass('am-active')) {
changed = false;
} else {
$parent.find('.am-active').removeClass('am-active')
}
}
if (changed) {
$input.prop('checked', !$element.hasClass('am-active')).trigger('change')
}
}
if (changed) {
$element.toggleClass('am-active');
if (!$element.hasClass('am-active')) {
$element.blur();
}
}
}, this), 0);
};
Button.prototype.toggle = function() {
var changed = true,
$element = this.$element,
$parent = this.$element.parent('.am-btn-group');
if ($parent.length) {
var $input = this.$element.find('input');
if ($input.prop('type') == 'radio') {
if ($input.prop('checked') && $element.hasClass('am-active')) {
changed = false;
} else {
$parent.find('.am-active').removeClass('am-active');
}
};
}
// Button plugin
function Plugin(option) {
return this.each(function() {
var $this = $(this);
var data = $this.data('amui.button');
var options = typeof option == 'object' && option || {};
if (!data) {
$this.data('amui.button', (data = new Button(this, options)));
}
if (option == 'toggle') {
data.toggle();
} else if (typeof option == 'string') {
data.setState(option)
}
});
if (changed) {
$input.prop('checked',
!$element.hasClass('am-active')).trigger('change');
}
}
$.fn.button = Plugin;
if (changed) {
$element.toggleClass('am-active');
if (!$element.hasClass('am-active')) {
$element.blur();
}
}
};
// Button plugin
function Plugin(option) {
return this.each(function() {
var $this = $(this);
var data = $this.data('amui.button');
var options = typeof option == 'object' && option || {};
if (!data) {
$this.data('amui.button', (data = new Button(this, options)));
}
if (option == 'toggle') {
data.toggle();
} else if (typeof option == 'string') {
data.setState(option);
}
});
}
$.fn.button = Plugin;
// Init code
// Init code
$(document).on('click.button.amui', '[data-am-button]', function(e) {
var $btn = $(e.target);
$(document).on('click.button.amui', '[data-am-button]', function(e) {
var $btn = $(e.target);
if (!$btn.hasClass('am-btn')) {
$btn = $btn.closest('.am-btn');
}
if (!$btn.hasClass('am-btn')) {
$btn = $btn.closest('.am-btn');
}
Plugin.call($btn, 'toggle');
e.preventDefault();
});
Plugin.call($btn, 'toggle');
e.preventDefault();
$(function() {
$('[data-am-loading]').each(function() {
$(this).button(UI.utils.parseOptions($(this).data('amLoading')));
});
});
$(function() {
$('[data-am-loading]').each(function() {
$(this).button(UI.utils.parseOptions($(this).data('amLoading')));
});
});
UI.button = Button;
module.exports = Button;
// TODO: 样式复查
module.exports = Button;
});
define(function(require, exports, module) {
'use strict';
'use strict';
require('core');
require('core');
var $ = window.Zepto,
UI = $.AMUI;
var $ = window.Zepto,
UI = $.AMUI;
/**
* @via https://github.com/twbs/bootstrap/blob/master/js/collapse.js
* @copyright (c) 2011-2014 Twitter, Inc
* @license The MIT License
*/
/**
* @via https://github.com/twbs/bootstrap/blob/master/js/collapse.js
* @copyright (c) 2011-2014 Twitter, Inc
* @license The MIT License
*/
var Collapse = function(element, options) {
this.$element = $(element);
this.options = $.extend({}, Collapse.DEFAULTS, options);
this.transitioning = null;
var Collapse = function (element, options) {
this.$element = $(element);
this.options = $.extend({}, Collapse.DEFAULTS, options);
this.transitioning = null;
if (this.options.parent) {
this.$parent = $(this.options.parent);
}
if (this.options.toggle) {
this.toggle();
}
};
Collapse.DEFAULTS = {
toggle: true
};
if (this.options.parent) {
this.$parent = $(this.options.parent);
}
Collapse.prototype.open = function () {
if (this.transitioning || this.$element.hasClass('am-in')) return;
if (this.options.toggle) {
this.toggle();
}
};
var startEvent = $.Event('open:collapse:amui');
this.$element.trigger(startEvent);
Collapse.DEFAULTS = {
toggle: true
};
if (startEvent.isDefaultPrevented()) return;
Collapse.prototype.open = function() {
if (this.transitioning || this.$element.hasClass('am-in')) {
return;
}
var actives = this.$parent && this.$parent.find('> .am-panel > .am-in');
var startEvent = $.Event('open:collapse:amui');
this.$element.trigger(startEvent);
if (actives && actives.length) {
var hasData = actives.data('amui.collapse');
if (startEvent.isDefaultPrevented()) {
return;
}
if (hasData && hasData.transitioning) return;
var actives = this.$parent && this.$parent.find('> .am-panel > .am-in');
Plugin.call(actives, 'close');
if (actives && actives.length) {
var hasData = actives.data('amui.collapse');
hasData || actives.data('amui.collapse', null);
}
if (hasData && hasData.transitioning) {
return;
}
this.$element
.removeClass('am-collapse')
.addClass('am-collapsing').height(0);
Plugin.call(actives, 'close');
this.transitioning = 1;
hasData || actives.data('amui.collapse', null);
}
var complete = function () {
this.$element
.removeClass('am-collapsing')
.addClass('am-collapse am-in').height('');
this.transitioning = 0;
this.$element
.trigger('opened:collapse:amui');
};
this.$element
.removeClass('am-collapse')
.addClass('am-collapsing').height(0);
if (!UI.support.transition) {
return complete.call(this);
}
this.transitioning = 1;
this.$element
.one(UI.support.transition.end, $.proxy(complete, this))
.emulateTransitionEnd(300).height(this.$element[0].scrollHeight);
var complete = function() {
this.$element
.removeClass('am-collapsing')
.addClass('am-collapse am-in').height('');
this.transitioning = 0;
this.$element
.trigger('opened:collapse:amui');
};
Collapse.prototype.close = function () {
if (this.transitioning || !this.$element.hasClass('am-in')) return;
var startEvent = $.Event('close:collapse:amui');
this.$element.trigger(startEvent);
if (!UI.support.transition) {
return complete.call(this);
}
if (startEvent.isDefaultPrevented()) return;
this.$element
.one(UI.support.transition.end, $.proxy(complete, this))
.emulateTransitionEnd(300).height(this.$element[0].scrollHeight);
};
this.$element.height(this.$element.height());
this.$element[0].offsetHeight;
Collapse.prototype.close = function() {
if (this.transitioning || !this.$element.hasClass('am-in')) {
return;
}
this.$element
.addClass('am-collapsing')
.removeClass('am-collapse')
.removeClass('am-in');
var startEvent = $.Event('close:collapse:amui');
this.$element.trigger(startEvent);
this.transitioning = 1;
if (startEvent.isDefaultPrevented()) {
return;
}
var complete = function () {
this.transitioning = 0;
this.$element
.trigger('closed:collapse:amui')
.removeClass('am-collapsing')
.addClass('am-collapse');
};
this.$element.height(this.$element.height());
this.$element[0].offsetHeight;
if (!UI.support.transition) {
return complete.call(this);
}
this.$element
.addClass('am-collapsing')
.removeClass('am-collapse')
.removeClass('am-in');
this.$element.height(0)
.one(UI.support.transition.end, $.proxy(complete, this))
.emulateTransitionEnd(350);
};
this.transitioning = 1;
Collapse.prototype.toggle = function () {
this[this.$element.hasClass('am-in') ? 'close' : 'open']();
var complete = function() {
this.transitioning = 0;
this.$element
.trigger('closed:collapse:amui')
.removeClass('am-collapsing')
.addClass('am-collapse');
};
UI.collapse = Collapse;
// Collapse Plugin
function Plugin(option) {
return this.each(function () {
var $this = $(this),
data = $this.data('amui.collapse'),
options = $.extend({}, Collapse.DEFAULTS, UI.utils.options($this.attr('data-am-collapse')), typeof option == 'object' && option);
if (!data && options.toggle && option == 'open') {
option = !option;
}
if (!data) {
$this.data('amui.collapse', (data = new Collapse(this, options)))
}
if (typeof option == 'string') {
data[option]()
}
});
if (!UI.support.transition) {
return complete.call(this);
}
$.fn.collapse = Plugin;
// Init code
$(document).on('click.collapse.amui', '[data-am-collapse]', function (e) {
var href,
$this = $(this),
options = UI.utils.options($this.attr('data-am-collapse')),
target = options.target
|| e.preventDefault()
|| (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '');
var $target = $(target);
var data = $target.data('amui.collapse');
var option = data ? 'toggle' : options;
var parent = options.parent;
var $parent = parent && $(parent);
if (!data || !data.transitioning) {
if ($parent) {
//'[data-am-collapse*="{parent: \'' + parent + '"]
$parent.find('[data-am-collapse]').not($this).addClass('am-collapsed');
}
$this[$target.hasClass('am-in') ? 'addClass' : 'removeClass']('am-collapsed');
}
Plugin.call($target, option);
this.$element.height(0)
.one(UI.support.transition.end, $.proxy(complete, this))
.emulateTransitionEnd(350);
};
Collapse.prototype.toggle = function() {
this[this.$element.hasClass('am-in') ? 'close' : 'open']();
};
// Collapse Plugin
function Plugin(option) {
return this.each(function() {
var $this = $(this),
data = $this.data('amui.collapse'),
options = $.extend({}, Collapse.DEFAULTS,
UI.utils.options($this.attr('data-am-collapse')),
typeof option == 'object' && option);
if (!data && options.toggle && option == 'open') {
option = !option;
}
if (!data) {
$this.data('amui.collapse', (data = new Collapse(this, options)));
}
if (typeof option == 'string') {
data[option]();
}
});
}
$.fn.collapse = Plugin;
// Init code
$(document).on('click.collapse.amui', '[data-am-collapse]', function(e) {
var href,
$this = $(this),
options = UI.utils.options($this.attr('data-am-collapse')),
target = options.target ||
e.preventDefault() ||
(href = $this.attr('href')) &&
href.replace(/.*(?=#[^\s]+$)/, '');
var $target = $(target);
var data = $target.data('amui.collapse');
var option = data ? 'toggle' : options;
var parent = options.parent;
var $parent = parent && $(parent);
if (!data || !data.transitioning) {
if ($parent) {
// '[data-am-collapse*="{parent: \'' + parent + '"]
$parent.find('[data-am-collapse]').not($this).addClass('am-collapsed');
}
$this[$target.hasClass('am-in') ? 'addClass' :
'removeClass']('am-collapsed');
}
Plugin.call($target, option);
});
UI.collapse = Collapse;
module.exports = Collapse;
module.exports = Collapse;
});
// TODO: 更好的 target 选择方式
\ No newline at end of file
// TODO: 更好的 target 选择方式
define(function(require, exports, module) {
'use strict';
require('core');
require('core');
var $ = window.Zepto,
UI = $.AMUI;
var $ = window.Zepto,
UI = $.AMUI,
$doc = $(document),
transition = UI.support.transition;
var $doc = $(document),
$html = $('html'),
transition = UI.support.transition;
var Dimmer = function() {
this.id = UI.utils.generateGUID('am-dimmer');
this.$element = $(Dimmer.DEFAULTS.tpl, {
id: this.id
});
/**
* 通用遮罩层
* @constructor
*/
this.inited = false;
this.scrollbarWidth = 0;
this.used = $([]);
};
var Dimmer = function() {
this.id = UI.utils.generateGUID('am-dimmer');
this.$element = $(Dimmer.DEFAULTS.tpl, {
id: this.id
});
Dimmer.DEFAULTS = {
tpl: '<div class="am-dimmer" data-am-dimmer></div>'
};
this.inited = false;
this.scrollbarWidth = 0;
this.used = $([]);
};
Dimmer.prototype.init = function() {
if (!this.inited) {
$(document.body).append(this.$element);
this.inited = true;
$doc.trigger('init:dimmer:amui');
}
Dimmer.DEFAULTS = {
tpl: '<div class="am-dimmer" data-am-dimmer></div>'
};
return this;
};
Dimmer.prototype.init = function() {
if (!this.inited) {
$(document.body).append(this.$element);
this.inited = true;
$doc.trigger('init:dimmer:amui');
}
Dimmer.prototype.open = function(relatedElement) {
if (!this.inited) {
this.init();
}
return this;
};
var $element = this.$element;
Dimmer.prototype.open = function(relatedElement) {
if (!this.inited) this.init();
// 用于多重调用
if (relatedElement) {
this.used = this.used.add($(relatedElement));
}
var $element = this.$element;
this.checkScrollbar().setScrollbar();
// 用于多重调用
if (relatedElement) {
this.used = this.used.add($(relatedElement));
}
$element.show().trigger('open:dimmer:amui');
this.checkScrollbar().setScrollbar();
setTimeout(function() {
$element.addClass('am-active');
}, 0);
$element.show().trigger('open:dimmer:amui');;
return this;
};
setTimeout(function() {
$element.addClass('am-active')
}, 0);
Dimmer.prototype.close = function(relatedElement, force) {
this.used = this.used.not($(relatedElement));
return this;
};
if (!force && this.used.length) {
return this;
}
Dimmer.prototype.close = function(relatedElement, force) {
this.used = this.used.not($(relatedElement));
var $element = this.$element;
if (!force && this.used.length) return this;
$element.removeClass('am-active').trigger('close:dimmer:amui');
var $element = this.$element;
function complete() {
this.resetScrollbar();
$element.hide();
}
$element.removeClass('am-active').trigger('close:dimmer:amui');
transition ? $element.one(transition.end, $.proxy(complete, this)) :
complete.call(this);
function complete() {
this.resetScrollbar();
$element.hide();
}
return this;
};
transition ? $element.one(transition.end, $.proxy(complete, this)) :
complete.call(this);
Dimmer.prototype.checkScrollbar = function() {
this.scrollbarWidth = UI.utils.measureScrollbar();
return this;
};
return this;
};
Dimmer.prototype.checkScrollbar = function () {
this.scrollbarWidth = UI.utils.measureScrollbar();
Dimmer.prototype.setScrollbar = function() {
var $body = $(document.body),
bodyPaddingRight = parseInt(($body.css('padding-right') || 0), 10);
return this;
};
if (this.scrollbarWidth) {
$body.css('padding-right', bodyPaddingRight + this.scrollbarWidth);
}
Dimmer.prototype.setScrollbar = function () {
var $body = $(document.body),
bodyPaddingRight = parseInt(($body.css('padding-right') || 0), 10);
$body.addClass('am-dimmer-active');
if (this.scrollbarWidth) $body.css('padding-right', bodyPaddingRight + this.scrollbarWidth);
return this;
};
$body.addClass('am-dimmer-active');
Dimmer.prototype.resetScrollbar = function() {
$(document.body).css('padding-right', '').removeClass('am-dimmer-active');
return this;
};
return this;
};
Dimmer.prototype.resetScrollbar = function () {
$(document.body).css('padding-right', '').removeClass('am-dimmer-active');
var dimmer = new Dimmer();
return this;
};
UI.dimmer = dimmer;
var dimmer = new Dimmer();
UI.dimmer = dimmer;
module.exports = dimmer;
module.exports = dimmer;
});
define(function(require, exports, module) {
'use strict';
require('core');
require('core');
var $ = window.Zepto,
UI = $.AMUI,
animation = UI.support.animation;
var $ = window.Zepto,
UI = $.AMUI,
animation = UI.support.animation;
/**
* @via https://github.com/Minwe/bootstrap/blob/master/js/dropdown.js
* @copyright (c) 2011-2014 Twitter, Inc
* @license The MIT License
*/
/**
* @via https://github.com/Minwe/bootstrap/blob/master/js/dropdown.js
* @copyright (c) 2011-2014 Twitter, Inc
* @license The MIT License
*/
var toggle = '[data-am-dropdown] > .am-dropdown-toggle';
// var toggle = '[data-am-dropdown] > .am-dropdown-toggle';
var Dropdown = function(element, options) {
this.options = $.extend({}, Dropdown.DEFAULTS, options);
var Dropdown = function(element, options) {
this.options = $.extend({}, Dropdown.DEFAULTS, options);
options = this.options;
options = this.options;
this.$element = $(element);
this.$toggle = this.$element.find(options.selector.toggle);
this.$dropdown = this.$element.find(options.selector.dropdown);
this.$boundary = (options.boundary === window) ? $(window) : this.$element.closest(options.boundary);
this.$justify = (options.justify && $(options.justify).length && $(options.justify)) || undefined;
this.$element = $(element);
this.$toggle = this.$element.find(options.selector.toggle);
this.$dropdown = this.$element.find(options.selector.dropdown);
this.$boundary = (options.boundary === window) ? $(window) :
this.$element.closest(options.boundary);
this.$justify = (options.justify && $(options.justify).length &&
$(options.justify)) || undefined;
!this.$boundary.length && (this.$boundary = $(window));
!this.$boundary.length && (this.$boundary = $(window));
this.active = this.$element.hasClass('am-active') ? true : false;
this.animating = null;
this.active = this.$element.hasClass('am-active') ? true : false;
this.animating = null;
this.events();
};
this.events();
};
Dropdown.DEFAULTS = {
animation: 'am-animation-slide-top-fixed',
boundary: window,
justify: undefined,
selector: {
dropdown: '.am-dropdown-content',
toggle: '.am-dropdown-toggle'
},
trigger: 'click'
};
Dropdown.DEFAULTS = {
animation: 'am-animation-slide-top-fixed',
boundary: window,
justify: undefined,
selector: {
dropdown: '.am-dropdown-content',
toggle: '.am-dropdown-toggle'
},
trigger: 'click'
};
Dropdown.prototype.toggle = function() {
this.clear();
Dropdown.prototype.toggle = function() {
this.clear();
if (this.animating) return;
if (this.animating) {
return;
}
this[this.active ? 'close' : 'open']();
};
this[this.active ? 'close' : 'open']();
};
Dropdown.prototype.open = function(e) {
var $toggle = this.$toggle,
$element = this.$element,
$dropdown = this.$dropdown;
Dropdown.prototype.open = function(e) {
var $toggle = this.$toggle,
$element = this.$element,
$dropdown = this.$dropdown;
if ($toggle.is('.am-disabled, :disabled')) return;
if ($toggle.is('.am-disabled, :disabled')) {
return;
}
if (this.active) return;
if (this.active) {
return;
}
$element.trigger('open:dropdown:amui').addClass('am-active');
$element.trigger('open:dropdown:amui').addClass('am-active');
$toggle.trigger('focus');
$toggle.trigger('focus');
this.checkDimensions();
this.checkDimensions();
var complete = $.proxy(function() {
$element.trigger('opened:dropdown:amui');
this.active = true;
this.animating = 0;
}, this);
var complete = $.proxy(function() {
$element.trigger('opened:dropdown:amui');
this.active = true;
this.animating = 0;
}, this);
if (animation) {
this.animating = 1;
$dropdown.addClass(this.options.animation).on(animation.end + '.open.dropdown.amui', $.proxy(function() {
complete();
$dropdown.removeClass(this.options.animation);
}, this));
} else {
complete();
}
};
Dropdown.prototype.close = function() {
if (!this.active) return;
var animationName = this.options.animation + ' am-animation-reverse',
$element = this.$element,
$dropdown = this.$dropdown;
$element.trigger('close:dropdown:amui');
var complete = $.proxy(function complete() {
$element.removeClass('am-active').trigger('closed:dropdown:amui');
this.active = false;
this.animating = 0;
this.$toggle.blur();
}, this);
if (animation) {
$dropdown.addClass(animationName);
this.animating = 1;
// animation
$dropdown.one(animation.end + '.close.dropdown.amui', function() {
complete();
$dropdown.removeClass(animationName);
});
} else {
if (animation) {
this.animating = 1;
$dropdown.addClass(this.options.animation).
on(animation.end + '.open.dropdown.amui', $.proxy(function() {
complete();
}
};
Dropdown.prototype.checkDimensions = function() {
if (!this.$dropdown.length) return;
var $dropdown = this.$dropdown,
offset = $dropdown.offset(),
width = $dropdown.outerWidth(),
boundaryWidth = this.$boundary.width(),
boundaryOffset = $.isWindow(this.boundary) && this.$boundary.offset() ? this.$boundary.offset().left : 0;
if (this.$justify) {
$dropdown.css({'min-width': this.$justify.width()});
}
if ((width + (offset.left - boundaryOffset)) > boundaryWidth) {
this.$element.addClass('am-dropdown-flip');
}
};
Dropdown.prototype.clear = function() {
$('[data-am-dropdown]').not(this.$element).each(function() {
var data = $(this).data('amui.dropdown');
data && data['close']();
});
};
Dropdown.prototype.events = function() {
var eventNS = 'dropdown.amui',
triggers = this.options.trigger.split(' '),
$toggle = this.$toggle;
$toggle.on('click.' + eventNS, $.proxy(this.toggle, this))
/*for (var i = triggers.length; i--;) {
var trigger = triggers[i];
if (trigger === 'click') {
$toggle.on('click.' + eventNS, $.proxy(this.toggle, this))
}
if (trigger === 'focus' || trigger === 'hover') {
var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
this.$element.on(eventIn + '.' + eventNS, $.proxy(this.open, this))
.on(eventOut + '.' + eventNS, $.proxy(this.close, this));
}
}*/
$(document).on('keydown.dropdown.amui', $.proxy(function(e) {
e.keyCode === 27 && this.active && this.close();
}, this)).on('click.outer.dropdown.amui', $.proxy(function(e) {
var $target = $(e.target);
if (this.active && (this.$element[0] === e.target || !this.$element.find(e.target).length)) {
this.close();
}
}, this));
};
UI.dropdown = Dropdown;
// Dropdown Plugin
function Plugin(option) {
return this.each(function() {
var $this = $(this),
data = $this.data('amui.dropdown'),
options = $.extend({}, UI.utils.parseOptions($this.attr('data-am-dropdown')), typeof option == 'object' && option);
if (!data) {
$this.data('amui.dropdown', (data = new Dropdown(this, options)));
}
if (typeof option == 'string') {
data[option]();
}
});
$dropdown.removeClass(this.options.animation);
}, this));
} else {
complete();
}
};
Dropdown.prototype.close = function() {
if (!this.active) {
return;
}
var animationName = this.options.animation + ' am-animation-reverse',
$element = this.$element,
$dropdown = this.$dropdown;
$element.trigger('close:dropdown:amui');
var complete = $.proxy(function complete() {
$element.
removeClass('am-active').
trigger('closed:dropdown:amui');
this.active = false;
this.animating = 0;
this.$toggle.blur();
}, this);
if (animation) {
$dropdown.addClass(animationName);
this.animating = 1;
// animation
$dropdown.one(animation.end + '.close.dropdown.amui', function() {
complete();
$dropdown.removeClass(animationName);
});
} else {
complete();
}
};
Dropdown.prototype.checkDimensions = function() {
if (!this.$dropdown.length) {
return;
}
$.fn.dropdown = Plugin;
var $dropdown = this.$dropdown,
offset = $dropdown.offset(),
width = $dropdown.outerWidth(),
boundaryWidth = this.$boundary.width(),
boundaryOffset = $.isWindow(this.boundary) && this.$boundary.offset() ?
this.$boundary.offset().left : 0;
if (this.$justify) {
$dropdown.css({'min-width': this.$justify.width()});
}
// Init code
if ((width + (offset.left - boundaryOffset)) > boundaryWidth) {
this.$element.addClass('am-dropdown-flip');
}
};
$(function() {
$('[data-am-dropdown]').dropdown();
Dropdown.prototype.clear = function() {
$('[data-am-dropdown]').not(this.$element).each(function() {
var data = $(this).data('amui.dropdown');
data && data['close']();
});
};
Dropdown.prototype.events = function() {
var eventNS = 'dropdown.amui',
// triggers = this.options.trigger.split(' '),
$toggle = this.$toggle;
$toggle.on('click.' + eventNS, $.proxy(this.toggle, this))
/*for (var i = triggers.length; i--;) {
var trigger = triggers[i];
if (trigger === 'click') {
$toggle.on('click.' + eventNS, $.proxy(this.toggle, this))
}
if (trigger === 'focus' || trigger === 'hover') {
var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
this.$element.on(eventIn + '.' + eventNS, $.proxy(this.open, this))
.on(eventOut + '.' + eventNS, $.proxy(this.close, this));
}
}*/
$(document).on('keydown.dropdown.amui', $.proxy(function(e) {
e.keyCode === 27 && this.active && this.close();
}, this)).on('click.outer.dropdown.amui', $.proxy(function(e) {
// var $target = $(e.target);
if (this.active && (this.$element[0] === e.target ||
!this.$element.find(e.target).length)) {
this.close();
}
}, this));
};
// Dropdown Plugin
function Plugin(option) {
return this.each(function() {
var $this = $(this),
data = $this.data('amui.dropdown'),
options = $.extend({},
UI.utils.parseOptions($this.attr('data-am-dropdown')),
typeof option == 'object' && option);
if (!data) {
$this.data('amui.dropdown', (data = new Dropdown(this, options)));
}
if (typeof option == 'string') {
data[option]();
}
});
}
$.fn.dropdown = Plugin;
// Init code
$(function() {
$('[data-am-dropdown]').dropdown();
});
$(document).on('click.dropdown.amui', '.am-dropdown form', function(e) {
e.stopPropagation();
});
UI.dropdown = Dropdown;
$(document).on('click.dropdown.amui', '.am-dropdown form', function(e) {
e.stopPropagation()
});
module.exports = Dropdown;
});
// TODO: 1. 处理链接 focus
......
此差异已折叠。
define(function(require, exports, module) {
require('core');
'use strict';
var dimmer = require('ui.dimmer'),
$ = window.Zepto,
UI = $.AMUI,
$doc = $(document),
supportTransition = UI.support.transition;
require('core');
/**
* @reference https://github.com/nolimits4web/Framework7/blob/master/src/js/modals.js
* @license https://github.com/nolimits4web/Framework7/blob/master/LICENSE
*/
var dimmer = require('ui.dimmer'),
$ = window.Zepto,
UI = $.AMUI,
$doc = $(document),
supportTransition = UI.support.transition;
var Modal = function(element, options) {
this.options = $.extend({}, Modal.DEFAULTS, options || {});
this.$element = $(element);
/**
* @reference https://github.com/nolimits4web/Framework7/blob/master/src/js/modals.js
* @license https://github.com/nolimits4web/Framework7/blob/master/LICENSE
*/
if (!this.$element.attr('id')) {
this.$element.attr('id', UI.utils.generateGUID('am-modal'))
}
var Modal = function(element, options) {
this.options = $.extend({}, Modal.DEFAULTS, options || {});
this.$element = $(element);
this.isPopup = this.$element.hasClass('am-popup');
this.active = this.transitioning = null;
this.events();
};
if (!this.$element.attr('id')) {
this.$element.attr('id', UI.utils.generateGUID('am-modal'));
}
Modal.DEFAULTS = {
className: {
active: 'am-modal-active',
out: 'am-modal-out'
},
selector: {
modal: '.am-modal',
active: '.am-modal-active'
},
cancelable: true,
onConfirm: function() {
},
onCancel: function() {
},
duration: 300, // must equal the CSS transition duration
transitionEnd: supportTransition.end && supportTransition.end + '.modal.amui'
};
this.isPopup = this.$element.hasClass('am-popup');
this.active = this.transitioning = null;
this.events();
};
Modal.DEFAULTS = {
className: {
active: 'am-modal-active',
out: 'am-modal-out'
},
selector: {
modal: '.am-modal',
active: '.am-modal-active'
},
cancelable: true,
onConfirm: function() {
},
onCancel: function() {
},
duration: 300, // must equal the CSS transition duration
transitionEnd: supportTransition.end &&
supportTransition.end + '.modal.amui'
};
Modal.prototype.toggle = function(relatedElement) {
return this.active ? this.close() : this.open(relatedElement);
};
Modal.prototype.open = function(relatedElement) {
var $element = this.$element,
options = this.options,
isPopup = this.isPopup;
if (this.active) {
return;
}
Modal.prototype.toggle = function(relatedElement) {
return this.active ? this.close() : this.open(relatedElement)
};
if (!this.$element.length) {
return;
}
Modal.prototype.open = function(relatedElement) {
var $element = this.$element,
options = this.options,
isPopup = this.isPopup;
// 判断如果还在动画,就先触发之前的closed事件
if (this.transitioning) {
clearTimeout($element.transitionEndTimmer);
$element.transitionEndTimmer = null;
$element.trigger(options.transitionEnd).off(options.transitionEnd);
}
if (this.active) return;
isPopup && this.$element.show();
if (!this.$element.length) return;
this.active = true;
// 判断如果还在动画,就先触发之前的closed事件
if (this.transitioning) {
clearTimeout($element.transitionEndTimmer);
$element.transitionEndTimmer = null;
$element.trigger(options.transitionEnd).off(options.transitionEnd);
}
$element.trigger($.Event('open:modal:amui',
{relatedElement: relatedElement}));
isPopup && this.$element.show();
dimmer.open($element);
this.active = true;
$element.show().redraw();
$element.trigger($.Event('open:modal:amui', {relatedElement: relatedElement}));
!isPopup && $element.css({
marginTop: -parseInt($element.height() / 2, 10) + 'px'
});
dimmer.open($element);
$element.
removeClass(options.className.out).
addClass(options.className.active);
$element.show().redraw();
this.transitioning = 1;
!isPopup && $element.css({marginTop: -parseInt($element.height() / 2, 10) + 'px'});
var complete = function() {
$element.trigger($.Event('opened:modal:amui',
{relatedElement: relatedElement}));
this.transitioning = 0;
};
$element.removeClass(options.className.out).addClass(options.className.active);
if (!supportTransition) {
return complete.call(this);
}
this.transitioning = 1;
$element.
one(options.transitionEnd, $.proxy(complete, this)).
emulateTransitionEnd(options.duration);
};
var complete = function() {
$element.trigger($.Event('opened:modal:amui', {relatedElement: relatedElement}));
this.transitioning = 0;
};
Modal.prototype.close = function(relatedElement) {
if (!this.active) {
return;
}
if (!supportTransition) return complete.call(this);
var $element = this.$element,
options = this.options,
isPopup = this.isPopup;
$element.one(options.transitionEnd, $.proxy(complete, this)).emulateTransitionEnd(options.duration);
};
// 判断如果还在动画,就先触发之前的opened事件
if (this.transitioning) {
clearTimeout($element.transitionEndTimmer);
$element.transitionEndTimmer = null;
$element.trigger(options.transitionEnd).off(options.transitionEnd);
}
Modal.prototype.close = function(relatedElement) {
if (!this.active) return;
this.$element.trigger($.Event('close:modal:amui',
{relatedElement: relatedElement}));
var $element = this.$element,
options = this.options,
isPopup = this.isPopup,
that = this;
this.transitioning = 1;
// 判断如果还在动画,就先触发之前的opened事件
if (this.transitioning) {
clearTimeout($element.transitionEndTimmer);
$element.transitionEndTimmer = null;
$element.trigger(options.transitionEnd).off(options.transitionEnd);
}
var complete = function() {
$element.trigger('closed:amui:modal');
isPopup && $element.removeClass(options.className.out);
$element.hide();
this.transitioning = 0;
};
this.$element.trigger($.Event('close:modal:amui', {relatedElement: relatedElement}));
$element.
removeClass(options.className.active).
addClass(options.className.out);
this.transitioning = 1;
if (!supportTransition) {
return complete.call(this);
}
var complete = function() {
$element.trigger('closed:amui:modal');
isPopup && $element.removeClass(options.className.out);
$element.hide();
this.transitioning = 0;
};
$element
.one(options.transitionEnd, $.proxy(complete, this))
.emulateTransitionEnd(options.duration);
$element.removeClass(options.className.active).addClass(options.className.out);
dimmer.close($element, true);
if (!supportTransition) return complete.call(this);
this.active = false;
};
$element
.one(options.transitionEnd, $.proxy(complete, this))
.emulateTransitionEnd(options.duration);
Modal.prototype.events = function() {
var that = this,
$element = this.$element,
$ipt = $element.find('.am-modal-prompt-input');
dimmer.close($element, true);
if (this.options.cancelable) {
$element.on('keyup.modal.amui',
$.proxy(function(e) {
if (this.active && e.which === 27) {
this.options.onCancel();
this.close();
}
}, that));
this.active = false;
};
dimmer.$element.on('click', function(e) {
that.close();
});
}
Modal.prototype.events = function() {
var that = this,
$element = this.$element,
$ipt = $element.find('.am-modal-prompt-input');
if (this.options.cancelable) {
$element.on('keyup.modal.amui',
$.proxy(function(e) {
if (this.active && e.which === 27) {
this.options.onCancel();
this.close();
}
}, that));
dimmer.$element.on('click', function(e) {
that.close();
});
}
// Close button
$element.find('[data-am-modal-close]').on('click.modal.amui', function(e) {
e.preventDefault();
that.close();
});
$element.find('.am-modal-btn').on('click.modal.amui', function(e) {
that.close();
});
$element.find('[data-am-modal-confirm]').on('click.modal.amui', function() {
that.options.onConfirm($ipt.val());
});
$element.find('[data-am-modal-cancel]').on('click.modal.amui', function() {
that.options.onCancel($ipt.val());
});
};
// Close button
$element.find('[data-am-modal-close]').on('click.modal.amui', function(e) {
e.preventDefault();
that.close();
});
$element.find('.am-modal-btn').on('click.modal.amui', function(e) {
that.close();
});
function Plugin(option, relatedElement) {
return this.each(function() {
var $this = $(this),
data = $this.data('am.modal'),
options = $.extend({}, Modal.DEFAULTS, typeof option == 'object' && option);
if (!data) {
$this.data('am.modal', (data = new Modal(this, options)));
}
$element.find('[data-am-modal-confirm]').on('click.modal.amui', function() {
that.options.onConfirm($ipt.val());
});
if (typeof option == 'string') {
data[option](relatedElement);
} else {
data.toggle(option && option.relatedElement || undefined);
}
});
}
$element.find('[data-am-modal-cancel]').on('click.modal.amui', function() {
that.options.onCancel($ipt.val());
});
};
function Plugin(option, relatedElement) {
return this.each(function() {
var $this = $(this),
data = $this.data('am.modal'),
options = $.extend({},
Modal.DEFAULTS, typeof option == 'object' && option);
if (!data) {
$this.data('am.modal', (data = new Modal(this, options)));
}
if (typeof option == 'string') {
data[option](relatedElement);
} else {
data.toggle(option && option.relatedElement || undefined);
}
});
}
$.fn.modal = Plugin;
$.fn.modal = Plugin;
$doc.on('click', '[data-am-modal]', function() {
var $this = $(this),
options = UI.utils.parseOptions($this.attr('data-am-modal')),
$target = $(options.target ||
(this.href && this.href.replace(/.*(?=#[^\s]+$)/, ''))),
option = $target.data('am.modal') ? 'toggle' : options;
$doc.on('click', '[data-am-modal]', function() {
var $this = $(this),
options = UI.utils.parseOptions($this.attr('data-am-modal')),
$target = $(options.target || (this.href && this.href.replace(/.*(?=#[^\s]+$)/, ''))),
option = $target.data('am.modal') ? 'toggle' : options;
Plugin.call($target, option, this);
});
Plugin.call($target, option, this);
});
UI.modal = Modal;
module.exports = Modal;
module.exports = Modal;
});
define(function(require, exports, module) {
'use strict';
require('zepto.outerdemension');
require('zepto.extend.data');
require('core');
var $ = window.Zepto,
UI = $.AMUI,
$win = $(window),
$doc = $(document),
scrollPos;
/**
* @via https://github.com/uikit/uikit/blob/master/src/js/offcanvas.js
* @license https://github.com/uikit/uikit/blob/master/LICENSE.md
*/
var OffCanvas = function(element, options) {
this.$element = $(element);
this.options = options;
this.events();
};
OffCanvas.DEFAULTS = {
duration: 300,
effect: 'overlay' // {push|overlay}, push is too expensive
};
OffCanvas.prototype.open = function(relatedElement) {
var _self = this,
$element = this.$element;
if (!$element.length || $element.hasClass('am-active')) return;
var effect = this.options.effect,
$html = $('html'),
$body = $('body'),
$bar = $element.find('.am-offcanvas-bar').first(),
dir = $bar.hasClass('am-offcanvas-bar-flip') ? -1 : 1;
$bar.addClass('am-offcanvas-bar-' + effect);
scrollPos = {x: window.scrollX, y: window.scrollY};
$element.addClass('am-active');
$body.css({width: window.innerWidth, height: $win.height()}).addClass('am-offcanvas-page');
if (!(effect === 'overlay')) {
$body.css({'margin-left': $bar.outerWidth() * dir}).width(); // force redraw
}
$html.css('margin-top', scrollPos.y * -1);
setTimeout(function(){
$bar.addClass('am-offcanvas-bar-active').width();
}, 0);
$doc.trigger('open:offcanvas:amui');
$element.off('.offcanvas.amui').on('click.offcanvas.amui swipe.offcanvas.amui', $.proxy(function(e) {
var $target = $(e.target);
if (!e.type.match(/swipe/)) {
if ($target.hasClass('am-offcanvas-bar')) return;
if ($target.parents('.am-offcanvas-bar').first().length) return;
}
'use strict';
require('zepto.outerdemension');
require('zepto.extend.data');
require('core');
var $ = window.Zepto,
UI = $.AMUI,
$win = $(window),
$doc = $(document),
scrollPos;
/**
* @via https://github.com/uikit/uikit/blob/master/src/js/offcanvas.js
* @license https://github.com/uikit/uikit/blob/master/LICENSE.md
*/
var OffCanvas = function(element, options) {
this.$element = $(element);
this.options = options;
this.events();
};
OffCanvas.DEFAULTS = {
duration: 300,
effect: 'overlay' // {push|overlay}, push is too expensive
};
OffCanvas.prototype.open = function(relatedElement) {
var $element = this.$element;
if (!$element.length || $element.hasClass('am-active')) {
return;
}
// https://developer.mozilla.org/zh-CN/docs/DOM/event.stopImmediatePropagation
e.stopImmediatePropagation();
var effect = this.options.effect,
$html = $('html'),
$body = $('body'),
$bar = $element.find('.am-offcanvas-bar').first(),
dir = $bar.hasClass('am-offcanvas-bar-flip') ? -1 : 1;
this.close();
}, this));
$bar.addClass('am-offcanvas-bar-' + effect);
$html.on('keydown.offcanvas.amui', $.proxy(function(e) {
if (e.keyCode === 27) { // ESC
this.close();
}
}, this));
};
OffCanvas.prototype.close = function(relatedElement) {
var $html = $('html'),
$body = $('body'),
$element = this.$element,
$bar = $element.find('.am-offcanvas-bar').first();
if (!$element.length || !$element.hasClass('am-active')) return;
$doc.trigger('close:offcanvas:amui');
function complete() {
$body.removeClass('am-offcanvas-page').css({width: '', height: '', 'margin-left': '', 'margin-right': ''});
$element.removeClass('am-active');
$bar.removeClass('am-offcanvas-bar-active');
$html.css('margin-top', '');
window.scrollTo(scrollPos.x, scrollPos.y);
$doc.trigger('closed:offcanvas:amui');
}
if (UI.support.transition) {
setTimeout(function(){
$bar.removeClass('am-offcanvas-bar-active');
}, 0);
$body.css('margin-left', '').one(UI.support.transition.end, function() {
complete();
}).emulateTransitionEnd(this.options.duration);
} else {
complete()
}
$element.off('.offcanvas.amui');
$html.off('.offcanvas.amui');
};
OffCanvas.prototype.events = function() {
$doc.on('click.offcanvas.amui', '[data-am-dismiss="offcanvas"]',
$.proxy(function(e) {
console.log('evbvvvv');
e.preventDefault();
this.close();
}, this));
return this;
};
UI.offcanvas = OffCanvas;
function Plugin(option, relatedElement) {
return this.each(function() {
var $this = $(this),
data = $this.data('am.offcanvas'),
options = $.extend({}, OffCanvas.DEFAULTS, typeof option == 'object' && option);
if (!data) {
$this.data('am.offcanvas', (data = new OffCanvas(this, options)));
data.open(relatedElement);
scrollPos = {x: window.scrollX, y: window.scrollY};
$element.addClass('am-active');
$body.
css({width: window.innerWidth, height: $win.height()}).
addClass('am-offcanvas-page');
if (effect !== 'overlay') {
$body.css({
'margin-left': $bar.outerWidth() * dir
}).width(); // force redraw
}
$html.css('margin-top', scrollPos.y * -1);
setTimeout(function() {
$bar.addClass('am-offcanvas-bar-active').width();
}, 0);
$doc.trigger('open:offcanvas:amui');
$element.off('.offcanvas.amui').
on('click.offcanvas.amui swipe.offcanvas.amui', $.proxy(function(e) {
var $target = $(e.target);
if (!e.type.match(/swipe/)) {
if ($target.hasClass('am-offcanvas-bar')) {
return;
}
if (typeof option == 'string') {
data[option] && data[option](relatedElement);
if ($target.parents('.am-offcanvas-bar').first().length) {
return;
}
});
}
// https://developer.mozilla.org/zh-CN/docs/DOM/event.stopImmediatePropagation
e.stopImmediatePropagation();
this.close();
}, this));
$html.on('keydown.offcanvas.amui', $.proxy(function(e) {
if (e.keyCode === 27) { // ESC
this.close();
}
}, this));
};
OffCanvas.prototype.close = function(relatedElement) {
var $html = $('html'),
$body = $('body'),
$element = this.$element,
$bar = $element.find('.am-offcanvas-bar').first();
if (!$element.length || !$element.hasClass('am-active')) {
return;
}
$doc.trigger('close:offcanvas:amui');
function complete() {
$body.removeClass('am-offcanvas-page').
css({width: '', height: '', 'margin-left': '', 'margin-right': ''});
$element.removeClass('am-active');
$bar.removeClass('am-offcanvas-bar-active');
$html.css('margin-top', '');
window.scrollTo(scrollPos.x, scrollPos.y);
$doc.trigger('closed:offcanvas:amui');
}
if (UI.support.transition) {
setTimeout(function() {
$bar.removeClass('am-offcanvas-bar-active');
}, 0);
$body.css('margin-left', '').one(UI.support.transition.end, function() {
complete();
}).emulateTransitionEnd(this.options.duration);
} else {
complete();
}
$.fn.offCanvas = Plugin;
$element.off('.offcanvas.amui');
$html.off('.offcanvas.amui');
};
// Init code
$doc.on('click.offcanvas.amui', '[data-am-offcanvas]', function(e) {
e.preventDefault();
var $this = $(this),
options = UI.utils.parseOptions($this.data('amOffcanvas')),
$target = $(options.target || (this.href && this.href.replace(/.*(?=#[^\s]+$)/, ''))),
option = $target.data('am.offcanvas') ? 'open' : options;
OffCanvas.prototype.events = function() {
$doc.on('click.offcanvas.amui', '[data-am-dismiss="offcanvas"]',
$.proxy(function(e) {
e.preventDefault();
this.close();
}, this));
return this;
};
function Plugin(option, relatedElement) {
return this.each(function() {
var $this = $(this),
data = $this.data('am.offcanvas'),
options = $.extend({}, OffCanvas.DEFAULTS,
typeof option == 'object' && option);
if (!data) {
$this.data('am.offcanvas', (data = new OffCanvas(this, options)));
data.open(relatedElement);
}
Plugin.call($target, option, this);
if (typeof option == 'string') {
data[option] && data[option](relatedElement);
}
});
}
$.fn.offCanvas = Plugin;
// Init code
$doc.on('click.offcanvas.amui', '[data-am-offcanvas]', function(e) {
e.preventDefault();
var $this = $(this),
options = UI.utils.parseOptions($this.data('amOffcanvas')),
$target = $(options.target ||
(this.href && this.href.replace(/.*(?=#[^\s]+$)/, ''))),
option = $target.data('am.offcanvas') ? 'open' : options;
Plugin.call($target, option, this);
});
UI.offcanvas = OffCanvas;
module.exports = OffCanvas;
module.exports = OffCanvas;
});
// TODO: 优化动画效果
// http://dbushell.github.io/Responsive-Off-Canvas-Menu/step4.html
\ No newline at end of file
// http://dbushell.github.io/Responsive-Off-Canvas-Menu/step4.html
define(function(require, exports, module) {
'use strict';
require('core');
var $ = window.Zepto,
UI = $.AMUI,
$w = $(window);
/**
* @reference https://github.com/nolimits4web/Framework7/blob/master/src/js/modals.js
* @license https://github.com/nolimits4web/Framework7/blob/master/LICENSE
*/
var Popover = function(element, options) {
this.options = $.extend({}, Popover.DEFAULTS, options || {});
this.$element = $(element);
this.active = null;
this.$popover = (this.options.target && $(this.options.target)) || null;
this.init();
this.events();
};
Popover.DEFAULTS = {
trigger: 'click',
content: '',
open: false,
target: undefined,
tpl: '<div class="am-popover">' +
'<div class="am-popover-inner"></div>' +
'<div class="am-popover-caret"></div></div>'
};
Popover.prototype.init = function() {
var me = this,
$element = this.$element,
$popover;
if (!this.options.target) {
this.$popover = this.getPopover();
this.setContent();
}
$popover = this.$popover;
$popover.appendTo($('body'));
this.sizePopover();
function sizePopover() {
me.sizePopover();
}
$(window).on('resize:popover:amui', UI.utils.debounce(sizePopover, 50));
$element.on('open:popover:amui', function() {
$(window).on('resize:popover:amui', UI.utils.debounce(sizePopover, 50));
});
require('core');
var $ = window.Zepto,
UI = $.AMUI,
$w = $(window),
$doc = $(document);
/**
* @reference https://github.com/nolimits4web/Framework7/blob/master/src/js/modals.js
* @license https://github.com/nolimits4web/Framework7/blob/master/LICENSE
*/
var Popover = function(element, options) {
this.options = $.extend({}, Popover.DEFAULTS, options || {});
this.$element = $(element);
this.active = null;
this.$popover = (this.options.target && $(this.options.target)) || null;
this.init();
this.events();
};
Popover.DEFAULTS = {
trigger: 'click',
content: '',
open: false,
target: undefined,
tpl: '<div class="am-popover"><div class="am-popover-inner"></div><div class="am-popover-caret"></div></div>'
};
Popover.prototype.init = function() {
var me = this,
$element = this.$element,
$popover;
if (!this.options.target) {
this.$popover = this.getPopover();
this.setContent();
}
$element.on('close:popover:amui', function() {
$(window).off('resize:popover:amui', sizePopover);
});
this.options.open && this.open();
};
Popover.prototype.sizePopover = function sizePopover() {
var $element = this.$element,
$popover = this.$popover;
$popover.appendTo($('body'));
if (!$popover || !$popover.length) {
return;
}
var popSize = $popover.getSize(),
popWidth = $popover.width() || popSize.width,
popHeight = $popover.height() || popSize.height,
$popCaret = $popover.find('.am-popover-caret'),
popCaretSize = ($popCaret.width() / 2) || 10,
popTotalHeight = popHeight + popCaretSize;
var triggerWidth = $element.outerWidth(),
triggerHeight = $element.outerHeight(),
triggerOffset = $element.offset(),
triggerRect = $element[0].getBoundingClientRect();
var winHeight = $w.height(),
winWidth = $w.width(),
popTop = 0,
popLeft = 0,
diff = 0,
spacing = 3,
popPosition = 'top';
$popover.css({left: '', top: ''})
.removeClass('am-popover-left am-popover-right am-popover-top am-popover-bottom');
$popCaret.css({left: '', top: ''});
if (popTotalHeight - spacing < triggerRect.top + spacing) { // on Top
popTop = triggerOffset.top - popTotalHeight - spacing;
} else if (popTotalHeight <
winHeight - triggerRect.top - triggerRect.height) {
// On bottom
popPosition = 'bottom';
popTop = triggerOffset.top + triggerHeight + popCaretSize + spacing;
} else { // On middle
popPosition = 'middle';
popTop = triggerHeight / 2 + triggerOffset.top - popHeight / 2;
}
this.sizePopover();
function sizePopover() {
me.sizePopover();
}
$(window).on('resize:popover:amui', UI.utils.debounce(sizePopover, 50));
$element.on('open:popover:amui', function() {
$(window).on('resize:popover:amui', UI.utils.debounce(sizePopover, 50));
});
$element.on('close:popover:amui', function() {
$(window).off('resize:popover:amui', sizePopover);
});
// Horizontal Position
if (popPosition === 'top' || popPosition === 'bottom') {
popLeft = triggerWidth / 2 + triggerOffset.left - popWidth / 2;
diff = popLeft;
if (popLeft < 5) {
popLeft = 5;
}
if (popLeft + popWidth > winWidth) {
popLeft = (winWidth - popWidth - 20);
// console.log('戳到边边了 left %d, win %d, popw %d', popLeft, winWidth, popWidth);
}
if (popPosition === 'top') {
$popover.addClass('am-popover-bottom');
}
if (popPosition === 'bottom') {
$popover.addClass('am-popover-top');
}
diff = diff - popLeft;
$popCaret.css({left: (popWidth / 2 - popCaretSize + diff) + 'px'});
} else if (popPosition === 'middle') {
popLeft = triggerOffset.left - popWidth - popCaretSize;
$popover.addClass('am-popover-left');
if (popLeft < 5) {
popLeft = triggerOffset.left + triggerWidth + popCaretSize;
$popover.removeClass('am-popover-left').addClass('am-popover-right');
}
if (popLeft + popWidth > winWidth) {
popLeft = winWidth - popWidth - 5;
$popover.removeClass('am-popover-left').addClass('am-popover-right');
}
$popCaret.css({top: (popHeight / 2 - popCaretSize / 2) + 'px'});
}
this.options.open && this.open();
};
Popover.prototype.sizePopover = function sizePopover() {
var $element = this.$element,
$popover = this.$popover;
if (!$popover || !$popover.length) return;
var popSize = $popover.getSize(),
popWidth = $popover.width() || popSize.width,
popHeight = $popover.height() || popSize.height,
$popCaret = $popover.find('.am-popover-caret'),
popCaretSize = ($popCaret.width() / 2) || 10,
popTotalHeight = popHeight + popCaretSize;
var triggerWidth = $element.outerWidth(),
triggerHeight = $element.outerHeight(),
triggerOffset = $element.offset(),
triggerRect = $element[0].getBoundingClientRect();
var winHeight = $w.height(),
winWidth = $w.width();
var popTop = 0,
popLeft = 0,
diff = 0,
spacing = 3,
popPosition = 'top';
$popover.css({left: '', top: ''})
.removeClass('am-popover-left am-popover-right am-popover-top am-popover-bottom');
$popCaret.css({left: '', top: ''});
if (popTotalHeight - spacing < triggerRect.top + spacing) { // on Top
popTop = triggerOffset.top - popTotalHeight - spacing;
} else if (popTotalHeight < winHeight - triggerRect.top - triggerRect.height) {
// On bottom
popPosition = 'bottom';
popTop = triggerOffset.top + triggerHeight + popCaretSize + spacing;
} else { // On middle
popPosition = 'middle';
popTop = triggerHeight / 2 + triggerOffset.top - popHeight / 2;
}
// Horizontal Position
if (popPosition === 'top' || popPosition === 'bottom') {
popLeft = triggerWidth / 2 + triggerOffset.left - popWidth / 2;
diff = popLeft;
if (popLeft < 5) popLeft = 5;
if (popLeft + popWidth > winWidth) {
popLeft = (winWidth - popWidth - 20);
// console.log('戳到边边了 left %d, win %d, popw %d', popLeft, winWidth, popWidth);
}
if (popPosition === 'top') $popover.addClass('am-popover-bottom');
if (popPosition === 'bottom') $popover.addClass('am-popover-top');
diff = diff - popLeft;
$popCaret.css({left: (popWidth / 2 - popCaretSize + diff) + 'px'});
} else if (popPosition === 'middle') {
popLeft = triggerOffset.left - popWidth - popCaretSize;
$popover.addClass('am-popover-left');
if (popLeft < 5) {
popLeft = triggerOffset.left + triggerWidth + popCaretSize;
$popover.removeClass('am-popover-left').addClass('am-popover-right');
}
if (popLeft + popWidth > winWidth) {
popLeft = winWidth - popWidth - 5;
$popover.removeClass('am-popover-left').addClass('am-popover-right');
}
$popCaret.css({top: (popHeight / 2 - popCaretSize / 2) + 'px'});
}
// Apply position style
$popover.css({top: popTop + 'px', left: popLeft + 'px'});
};
Popover.prototype.toggle = function() {
return this[this.active ? 'close' : 'open']();
};
Popover.prototype.open = function() {
var $popover = this.$popover;
this.$element.trigger('open:popover:amui');
this.sizePopover();
$popover.show().addClass('am-active');
this.active = true;
};
Popover.prototype.close = function() {
var $popover = this.$popover;
this.$element.trigger('close:popover:amui');
$popover
.removeClass('am-active')
.trigger('closed:popover:amui')
.hide();
this.active = false;
};
Popover.prototype.getPopover = function() {
var uid = UI.utils.generateGUID('am-popover');
return $(this.options.tpl, {
id: uid
});
};
Popover.prototype.setContent = function() {
this.$popover && this.$popover.find('.am-popover-inner').empty().html(this.options.content);
};
Popover.prototype.events = function() {
var eventNS = 'popover.amui',
triggers = this.options.trigger.split(' ');
for (var i = triggers.length; i--;) {
var trigger = triggers[i];
if (trigger === 'click') {
this.$element.on('click.' + eventNS, $.proxy(this.toggle, this))
} else { // hover or focus
var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
this.$element.on(eventIn + '.' + eventNS, $.proxy(this.open, this));
this.$element.on(eventOut + '.' + eventNS, $.proxy(this.close, this));
}
}
};
UI.popover = Popover;
function Plugin(option) {
return this.each(function() {
var $this = $(this),
data = $this.data('am.popover'),
options = $.extend({}, UI.utils.parseOptions($this.attr('data-am-popover')), typeof option == 'object' && option);
if (!data) {
$this.data('am.popover', (data = new Popover(this, options)));
}
if (typeof option == 'string') {
data[option]();
}
});
}
$.fn.popover = Plugin;
// Init code
$(function() {
$('[data-am-popover]').popover();
});
module.exports = Popover;
// Apply position style
$popover.css({top: popTop + 'px', left: popLeft + 'px'});
};
Popover.prototype.toggle = function() {
return this[this.active ? 'close' : 'open']();
};
Popover.prototype.open = function() {
var $popover = this.$popover;
this.$element.trigger('open:popover:amui');
this.sizePopover();
$popover.show().addClass('am-active');
this.active = true;
};
Popover.prototype.close = function() {
var $popover = this.$popover;
this.$element.trigger('close:popover:amui');
$popover
.removeClass('am-active')
.trigger('closed:popover:amui')
.hide();
this.active = false;
};
Popover.prototype.getPopover = function() {
var uid = UI.utils.generateGUID('am-popover');
return $(this.options.tpl, {
id: uid
});
};
Popover.prototype.setContent = function() {
this.$popover &&
this.$popover.find('.am-popover-inner').empty().
html(this.options.content);
};
Popover.prototype.events = function() {
var eventNS = 'popover.amui',
triggers = this.options.trigger.split(' ');
for (var i = triggers.length; i--;) {
var trigger = triggers[i];
if (trigger === 'click') {
this.$element.on('click.' + eventNS, $.proxy(this.toggle, this))
} else { // hover or focus
var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
this.$element.on(eventIn + '.' + eventNS, $.proxy(this.open, this));
this.$element.on(eventOut + '.' + eventNS, $.proxy(this.close, this));
}
}
)
;
};
function Plugin(option) {
return this.each(function() {
var $this = $(this),
data = $this.data('am.popover'),
options = $.extend({}, UI.utils.parseOptions($this.attr('data-am-popover')), typeof option == 'object' && option);
if (!data) {
$this.data('am.popover', (data = new Popover(this, options)));
}
if (typeof option == 'string') {
data[option]();
}
});
}
$.fn.popover = Plugin;
// Init code
$(function() {
$('[data-am-popover]').popover();
});
UI.popover = Popover;
module.exports = Popover;
});
此差异已折叠。
此差异已折叠。
define(function(require, exports, module) {
'use strict';
'use strict';
require('core');
require('core');
var $ = window.Zepto,
UI = $.AMUI;
var $ = window.Zepto,
UI = $.AMUI;
/**
* @via https://github.com/uikit/uikit/blob/master/src/js/scrollspy.js
* @license https://github.com/uikit/uikit/blob/master/LICENSE.md
*/
var ScrollSpy = function(element, options) {
if (!UI.support.animation) {
return;
}
/**
* @via https://github.com/uikit/uikit/blob/master/src/js/scrollspy.js
* @license https://github.com/uikit/uikit/blob/master/LICENSE.md
*/
var ScrollSpy = function(element, options) {
if (!UI.support.animation) return;
this.options = $.extend({}, ScrollSpy.DEFAULTS, options);
this.$element = $(element);
var checkViewRAF = function() {
UI.utils.rAF.call(window, $.proxy(this.checkView, this));
}.bind(this);
this.$window = $(window).on('scroll.scrollspy.amui', checkViewRAF)
.on('resize.scrollspy.amui orientationchange.scrollspy.amui', UI.utils.debounce(checkViewRAF, 50));
this.timer = this.inViewState = this.initInView = null;
checkViewRAF();
};
ScrollSpy.DEFAULTS = {
animation: 'fade',
className: {
inView: 'am-scrollspy-inview',
init: 'am-scrollspy-init'
},
repeat: true,
delay: 0,
topOffset: 0,
leftOffset: 0
};
ScrollSpy.prototype.checkView = function () {
var $element = this.$element,
options = this.options,
inView = UI.utils.isInView($element, options),
animation = (options.animation) ? ' am-animation-' + options.animation : '';
if(inView && !this.inViewState) {
if(this.timer) clearTimeout(this.timer);
if(!this.initInView) {
$element.addClass(options.className.init);
this.offset = $element.offset();
this.initInView = true;
$element.trigger('init:scrollspy:amui');
}
this.timer = setTimeout(function(){
if(inView) {
$element.addClass(options.className.inView + animation).width();
}
}, options.delay);
this.inViewState = true;
$element.trigger('inview:scrollspy:amui');
}
if (!inView && this.inViewState && options.repeat) {
$element.removeClass(options.className.inView + animation);
this.inViewState = false;
$element.trigger('outview:scrollspy:amui');
this.options = $.extend({}, ScrollSpy.DEFAULTS, options);
this.$element = $(element);
var checkViewRAF = function() {
UI.utils.rAF.call(window, $.proxy(this.checkView, this));
}.bind(this);
this.$window = $(window).on('scroll.scrollspy.amui', checkViewRAF)
.on('resize.scrollspy.amui orientationchange.scrollspy.amui',
UI.utils.debounce(checkViewRAF, 50));
this.timer = this.inViewState = this.initInView = null;
checkViewRAF();
};
ScrollSpy.DEFAULTS = {
animation: 'fade',
className: {
inView: 'am-scrollspy-inview',
init: 'am-scrollspy-init'
},
repeat: true,
delay: 0,
topOffset: 0,
leftOffset: 0
};
ScrollSpy.prototype.checkView = function() {
var $element = this.$element,
options = this.options,
inView = UI.utils.isInView($element, options),
animation = (options.animation) ?
' am-animation-' + options.animation : '';
if (inView && !this.inViewState) {
if (this.timer) {
clearTimeout(this.timer);
}
if (!this.initInView) {
$element.addClass(options.className.init);
this.offset = $element.offset();
this.initInView = true;
$element.trigger('init:scrollspy:amui');
}
this.timer = setTimeout(function() {
if (inView) {
$element.addClass(options.className.inView + animation).width();
}
};
ScrollSpy.prototype.check = function() {
UI.utils.rAF.call(window, $.proxy(this.checkView, this));
};
UI.scrollspy = ScrollSpy;
}, options.delay);
this.inViewState = true;
$element.trigger('inview:scrollspy:amui');
}
// Sticky Plugin
if (!inView && this.inViewState && options.repeat) {
$element.removeClass(options.className.inView + animation);
function Plugin(option) {
return this.each(function () {
var $this = $(this),
data = $this.data('am.scrollspy'),
options = typeof option == 'object' && option;
this.inViewState = false;
if (!data) $this.data('am.scrollspy', (data = new ScrollSpy(this, options)));
if (typeof option == 'string') data[option]();
});
$element.trigger('outview:scrollspy:amui');
}
};
ScrollSpy.prototype.check = function() {
UI.utils.rAF.call(window, $.proxy(this.checkView, this));
};
// Sticky Plugin
function Plugin(option) {
return this.each(function() {
var $this = $(this),
data = $this.data('am.scrollspy'),
options = typeof option == 'object' && option;
if (!data) {
$this.data('am.scrollspy', (data = new ScrollSpy(this, options)));
}
if (typeof option == 'string') {
data[option]();
}
});
}
$.fn.scrollspy = Plugin;
// Init code
$.fn.scrollspy = Plugin;
$(function() {
$('[data-am-scrollspy]').each(function () {
var $this = $(this),
options = UI.utils.options($this.attr('data-am-scrollspy'));
// Init code
$(function() {
$('[data-am-scrollspy]').each(function() {
var $this = $(this),
options = UI.utils.options($this.attr('data-am-scrollspy'));
$this.scrollspy(options);
});
$this.scrollspy(options);
});
});
UI.scrollspy = ScrollSpy;
module.exports = ScrollSpy;
module.exports = ScrollSpy;
});
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
define(function(require, exports, module) {
'use strict';
'use strict';
require('core');
require('core');
var $ = window.Zepto,
UI = $.AMUI;
var $ = window.Zepto,
UI = $.AMUI;
var cookie = {
get: function(name) {
var cookieName = encodeURIComponent(name) + "=",
cookieStart = document.cookie.indexOf(cookieName),
cookieValue = null,
cookieEnd;
var cookie = {
get: function(name) {
var cookieName = encodeURIComponent(name) + '=',
cookieStart = document.cookie.indexOf(cookieName),
cookieValue = null,
cookieEnd;
if (cookieStart > -1) {
cookieEnd = document.cookie.indexOf(";", cookieStart);
if (cookieEnd == -1) {
cookieEnd = document.cookie.length;
}
cookieValue = decodeURIComponent(document.cookie.substring(cookieStart + cookieName.length, cookieEnd));
}
if (cookieStart > -1) {
cookieEnd = document.cookie.indexOf(';', cookieStart);
if (cookieEnd == -1) {
cookieEnd = document.cookie.length;
}
cookieValue = decodeURIComponent(document.cookie.substring(cookieStart +
cookieName.length, cookieEnd));
}
return cookieValue;
},
return cookieValue;
},
set: function(name, value, expires, path, domain, secure) {
var cookieText = encodeURIComponent(name) + "=" + encodeURIComponent(value);
set: function(name, value, expires, path, domain, secure) {
var cookieText = encodeURIComponent(name) + '=' +
encodeURIComponent(value);
if (expires instanceof Date) {
cookieText += "; expires=" + expires.toGMTString();
}
if (expires instanceof Date) {
cookieText += '; expires=' + expires.toGMTString();
}
if (path) {
cookieText += "; path=" + path;
}
if (path) {
cookieText += '; path=' + path;
}
if (domain) {
cookieText += "; domain=" + domain;
}
if (domain) {
cookieText += '; domain=' + domain;
}
if (secure) {
cookieText += "; secure";
}
if (secure) {
cookieText += '; secure';
}
document.cookie = cookieText;
},
document.cookie = cookieText;
},
unset: function(name, path, domain, secure) {
this.set(name, "", new Date(0), path, domain, secure);
}
};
unset: function(name, path, domain, secure) {
this.set(name, '', new Date(0), path, domain, secure);
}
};
UI.utils.cookie = cookie;
UI.utils.cookie = cookie;
module.exports = cookie;
module.exports = cookie;
});
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
define(function(require, exports, module) {
var $ = window.Zepto;
var $ = window.Zepto;
// Create outerHeight and outerWidth methods
['width', 'height'].forEach(function(dimension) {
var offset, Dimension = dimension.replace(/./, function(m) {
return m[0].toUpperCase()
});
$.fn['outer' + Dimension] = function(margin) {
var elem = this;
if (elem) {
var size = elem[dimension]();
var sides = {'width': ['left', 'right'], 'height': ['top', 'bottom']};
sides[dimension].forEach(function(side) {
if (margin) size += parseInt(elem.css('margin-' + side), 10);
});
return size;
} else {
return null;
}
};
// Create outerHeight and outerWidth methods
['width', 'height'].forEach(function(dimension) {
var offset, Dimension = dimension.replace(/./, function(m) {
return m[0].toUpperCase()
});
$.fn['outer' + Dimension] = function(margin) {
var elem = this;
if (elem) {
var size = elem[dimension]();
var sides = {'width': ['left', 'right'], 'height': ['top', 'bottom']};
sides[dimension].forEach(function(side) {
if (margin) size += parseInt(elem.css('margin-' + side), 10);
});
return size;
} else {
return null;
}
};
});
});
此差异已折叠。
此差异已折叠。
define(function (require, exports, module) {
});
\ No newline at end of file
});
define(function(require, exports, module) {
var $ = window.Zepto;
var $ = window.Zepto;
});
\ No newline at end of file
});
define(function(require, exports, module) {
});
\ No newline at end of file
});
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
define(function (require, exports, module) {
var $ = window.Zepto;
define(function(require, exports, module) {
'use strict';
// hello world.
});
define(function(require, exports, module) {
});
\ No newline at end of file
});
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
define(function(require, exports, module) {
var $ = window.Zepto;
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册