Skip to content

Commit

Permalink
Removed IE9 support, the animate function and optmised
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbegent committed Mar 21, 2015
1 parent fecb056 commit 32bfffe
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 241 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ svelte - A lightweight modern JavaScript library
What is svelte?
---------------------

It is a lightweight modern JavaScript library (4.33KB minified) intended for use on projects where legacy browser support is not necessary.
It is a lightweight modern JavaScript library (4.34KB minified) intended for use on projects where legacy browser support is not necessary.

It uses mordern JavaScript (querySelectorAll, forEach, classList, matchesSelector) to help make it as lightweight as possible and therefore only works on the latest version of mordern browsers E.g. Chrome, Firefox, Opera, IE9+.
It uses mordern JavaScript (querySelectorAll, classList, matchesSelector) to help make it as lightweight as possible and therefore only works on the latest version of mordern browsers E.g. Chrome, Firefox, Opera, IE10+.

Getting Started
---------------------
Expand Down Expand Up @@ -68,7 +68,6 @@ API
* width()
* position()
* matches(selector)
* animate(name, callback) - currently fadeIn, fadeOut, pulse and shake, however you can add more

Custom functions
---------------------
Expand Down
150 changes: 0 additions & 150 deletions animate.css

This file was deleted.

2 changes: 1 addition & 1 deletion gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(grunt) {
dist : {
options: {
sourceMap: true,
banner: '/*** svelte - 1.1.2 ***/'
banner: '/*** svelte - 1.2.0 ***/'
},
files: {
'svelte.min.js': ['svelte.js'],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svelte",
"version": "1.1.2",
"version": "1.2.0",
"repository": {
"type": "git",
"url": "https://github.com/mattbegent/svelte.git"
Expand Down
77 changes: 12 additions & 65 deletions svelte.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @fileOverview svelte - the lightweight modern JavaScript framework
* @author Matt Begent
* @version 1.1.2
* @version 1.2.0
*/

(function (window, document) {
Expand Down Expand Up @@ -36,9 +36,9 @@ var svelte = {
* $('.each').each(function() { });
*/
each: function(callback) {
[].forEach.call(this.selector, function(el) {
callback(el);
});
for (var i = 0; i < this.selector.length; i++) {
callback(this.selector[i]);
}
return this;
},

Expand Down Expand Up @@ -138,11 +138,7 @@ var svelte = {
*/
addClass: function(className) {
return this.each(function(el) {
if (el.classList) {
el.classList.add(className);
} else { // IE9
el.className += ' ' + className;
}
el.classList.add(className);
});
},

Expand All @@ -156,11 +152,7 @@ var svelte = {
*/
removeClass: function(className) {
return this.each(function(el) {
if (el.classList) {
el.classList.remove(className);
} else { // IE9
el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
}
el.classList.remove(className);
});
},

Expand All @@ -174,22 +166,7 @@ var svelte = {
*/
toggleClass: function(className) {
return this.each(function(el) {
if(el.classList) {
el.classList.toggle(className);
} else { // IE9

var classes = el.className.split(' ');
var existingIndex = classes.indexOf(className);

if (existingIndex >= 0) {
classes.splice(existingIndex, 1);
} else {
classes.push(className);
}

el.className = classes.join(' ');

}
el.classList.toggle(className);
});
},

Expand All @@ -201,12 +178,8 @@ var svelte = {
* $('.class').hasClass('another-class');
*/
hasClass: function(className) {
var firstSelector = this.selector[0];
if(firstSelector.classList) {
return firstSelector.classList.contains(className);
} else {
return new RegExp('(^| )' + className + '( |$)', 'gi').test(firstSelector.className);
}
return this.selector[0].classList.contains(className);

},

/**
Expand Down Expand Up @@ -583,7 +556,7 @@ var svelte = {
/**
* Get the height of the first element in the selector
* @memberOf svelte
* @returns height
* @returns number height
* @example
* $('.height').height();
*/
Expand All @@ -594,7 +567,7 @@ var svelte = {
/**
* Get the width of the first element in the selector
* @memberOf svelte
* @returns height
* @returns number width
* @example
* $('.width').width();
*/
Expand Down Expand Up @@ -626,32 +599,6 @@ var svelte = {
// Tidy up
Element.prototype.matches = Element.prototype.matches || Element.prototype.matchesSelector || Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.webkitMatchesSelector;
return el.matches(selector);
},

/**
* Animates elements using CSS a callback
* @memberOf svelte
* @param {string} name Name of animation
* @param {function} callback Callback after animation is complete
* @returns Svelte
* @example
* $('.animate').animate('fadeIn', function() { console.log('Complete'); });
*/
animate: function(name, callback) {

var current = this;
current.removeClass('sv-' + name);

function animationCallback() {
if(callback) {
callback();
}
if(name !== 'fadeOut') { // fadeOut retains state
current.removeClass('sv-' + name);
}
}

current.addClass('sv-' + name).one('animationend', animationCallback).one('webkitAnimationEnd', animationCallback);
}

};
Expand All @@ -676,7 +623,7 @@ function $(selector, context) {
value: 'svelte'
},
version: {
value: '1.1.1'
value: '1.2.0'
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions svelte.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 32bfffe

Please sign in to comment.