From a59a93ad67036ad01428d5c3028065ec8c8f9075 Mon Sep 17 00:00:00 2001 From: Eunice Date: Thu, 9 Oct 2014 09:07:30 -0400 Subject: [PATCH 1/9] React-Assignment React-Assignment --- demo.html | 50 +++++++++++++ jquery.simplyCountable.js | 137 ++++++++++++++++++++++++++++++++++++ simplyCountable.jquery.json | 31 ++++++++ 3 files changed, 218 insertions(+) create mode 100644 demo.html create mode 100644 jquery.simplyCountable.js create mode 100644 simplyCountable.jquery.json diff --git a/demo.html b/demo.html new file mode 100644 index 0000000..dbb9088 --- /dev/null +++ b/demo.html @@ -0,0 +1,50 @@ + + + + + jquery.simplyCountable.js demo + + + + + + + +

Simply Countable +
+
User Test 1 +

You have characters left.

+
How many characters are left?
+

+

+
+
+
+
User Test 2 +

You have used words.

+
How many words typed?
+

+

+
+
+ + \ No newline at end of file diff --git a/jquery.simplyCountable.js b/jquery.simplyCountable.js new file mode 100644 index 0000000..7c1d577 --- /dev/null +++ b/jquery.simplyCountable.js @@ -0,0 +1,137 @@ +/* +* jQuery Simply Countable plugin +* Provides a character counter for any text input or textarea +* +* @version 0.4.2 +* @homepage http://github.com/aaronrussell/jquery-simply-countable/ +* @author Aaron Russell (http://www.aaronrussell.co.uk) +* +* Copyright (c) 2009-2010 Aaron Russell (aaron@gc4.co.uk) +* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) +* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. +*/ + +(function($){ + + $.fn.simplyCountable = function(options){ + + options = $.extend({ + counter: '#counter', + countType: 'characters', + maxCount: 140, + strictMax: false, + countDirection: 'down', + safeClass: 'safe', + overClass: 'over', + thousandSeparator: ',', + onOverCount: function(){}, + onSafeCount: function(){}, + onMaxCount: function(){} + }, options); + + var navKeys = [33,34,35,36,37,38,39,40]; + + return $(this).each(function(){ + + var countable = $(this); + var counter = $(options.counter); + if (!counter.length) { return false; } + + var countCheck = function(){ + + var count; + var revCount; + + var reverseCount = function(ct){ + return ct - (ct*2) + options.maxCount; + } + + var countInt = function(){ + return (options.countDirection === 'up') ? revCount : count; + } + + var numberFormat = function(ct){ + var prefix = ''; + if (options.thousandSeparator){ + ct = ct.toString(); + // Handle large negative numbers + if (ct.match(/^-/)) { + ct = ct.substr(1); + prefix = '-'; + } + for (var i = ct.length-3; i > 0; i -= 3){ + ct = ct.substr(0,i) + options.thousandSeparator + ct.substr(i); + } + } + return prefix + ct; + } + + var changeCountableValue = function(val){ + countable.val(val).trigger('change'); + } + + /* Calculates count for either words or characters */ + if (options.countType === 'words'){ + count = options.maxCount - $.trim(countable.val()).split(/\s+/).length; + if (countable.val() === ''){ count += 1; } + } + else { count = options.maxCount - countable.val().length; } + revCount = reverseCount(count); + + /* If strictMax set restrict further characters */ + if (options.strictMax && count <= 0){ + var content = countable.val(); + if (count < 0) { + options.onMaxCount(countInt(), countable, counter); + } + if (options.countType === 'words'){ + var allowedText = content.match( new RegExp('\\s?(\\S+\\s+){'+ options.maxCount +'}') ); + if (allowedText) { + changeCountableValue(allowedText[0]); + } + } + else { changeCountableValue(content.substring(0, options.maxCount)); } + count = 0, revCount = options.maxCount; + } + + counter.text(numberFormat(countInt())); + + /* Set CSS class rules and API callbacks */ + if (!counter.hasClass(options.safeClass) && !counter.hasClass(options.overClass)){ + if (count < 0){ counter.addClass(options.overClass); } + else { counter.addClass(options.safeClass); } + } + else if (count < 0 && counter.hasClass(options.safeClass)){ + counter.removeClass(options.safeClass).addClass(options.overClass); + options.onOverCount(countInt(), countable, counter); + } + else if (count >= 0 && counter.hasClass(options.overClass)){ + counter.removeClass(options.overClass).addClass(options.safeClass); + options.onSafeCount(countInt(), countable, counter); + } + + }; + + countCheck(); + + countable.on('keyup blur paste', function(e) { + switch(e.type) { + case 'keyup': + // Skip navigational key presses + if ($.inArray(e.which, navKeys) < 0) { countCheck(); } + break; + case 'paste': + // Wait a few miliseconds if a paste event + setTimeout(countCheck, (e.type === 'paste' ? 5 : 0)); + break; + default: + countCheck(); + break; + } + }); + + }); + + }; + +})(jQuery); \ No newline at end of file diff --git a/simplyCountable.jquery.json b/simplyCountable.jquery.json new file mode 100644 index 0000000..48e1e27 --- /dev/null +++ b/simplyCountable.jquery.json @@ -0,0 +1,31 @@ +{ + "name": "simplyCountable", + "version": "0.5.0", + "title": "jQuery Simply Countable", + "description": "jQuery plugin that provides a character counter for any text input or textarea.", + "author": { + "name": "Aaron Russell", + "url": "http://aaronrussell.co.uk" + }, + "keywords": [ + "forms", + "input", + "textarea", + "counter" + ], + "dependencies": { + "jquery": ">=1.4" + }, + "licenses": [ + { + "type": "MIT", + "url": "http://www.opensource.org/licenses/mit-license.php" + }, + { + "type": "GPL", + "url": "http://www.opensource.org/licenses/gpl-license.php" + } + ], + "homepage": "https://github.com/aaronrussell/jquery-simply-countable", + "bugs": "https://github.com/aaronrussell/jquery-simply-countable/issues" +} \ No newline at end of file From 665e797c97a375b9619e92fca00d492687f1cd68 Mon Sep 17 00:00:00 2001 From: Eunice Date: Fri, 31 Oct 2014 03:58:54 -0400 Subject: [PATCH 2/9] Delete .gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 3168ea5..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules/ -validation-* From 0c39196f788cb679d18d1afb900b0e9c018e0da3 Mon Sep 17 00:00:00 2001 From: Eunice Date: Fri, 31 Oct 2014 03:59:03 -0400 Subject: [PATCH 3/9] Delete .travis.yml --- .travis.yml | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b689349..0000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -language: node_js -node_js: -- '0.10' -branches: - only: - - /.*/ -before_install: npm install -g grunt-cli From 1b494a4534427325569eaab69e72981115d3ad9e Mon Sep 17 00:00:00 2001 From: Eunice Date: Fri, 31 Oct 2014 03:59:21 -0400 Subject: [PATCH 4/9] Delete Gruntfile.js --- Gruntfile.js | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 Gruntfile.js diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index df8bc7e..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,45 +0,0 @@ -module.exports = function(grunt) { - grunt.initConfig({ - jshint: { - files: { - src: [ - '**/.html', - '**/*.js', - // excluded files - '!node_modules/**/*', - '!vendor/**/*' - ] - }, - // http://www.jshint.com/docs/options/ - options: { - browser: true, - eqeqeq: true, - extract: 'auto', // http://bahmutov.calepin.co/linting-javascript-inside-html.html - forin: true, - freeze: true, - latedef: true, - maxdepth: 4, - maxparams: 3, - maxstatements: 10, - newcap: true - } - }, - validation: { - options: { - failHard: true, - reset: true - }, - files: { - src: [ - '**/*.html', - '!node_modules/**/*' - ] - } - } - }); - - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-html-validation'); - - grunt.registerTask('default', ['jshint', 'validation']); -}; From 80fcef411ab82a046980115f7dfc0c8778528101 Mon Sep 17 00:00:00 2001 From: Eunice Date: Fri, 31 Oct 2014 03:59:46 -0400 Subject: [PATCH 5/9] Delete index.html --- index.html | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 index.html diff --git a/index.html b/index.html deleted file mode 100644 index 3678415..0000000 --- a/index.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - So-and-so's React Assignment - - - YOUR PROJECT HERE - - From 3e3f918dfcd08ebea32dd2149e82245fa1ff7bac Mon Sep 17 00:00:00 2001 From: Eunice Date: Fri, 31 Oct 2014 04:02:21 -0400 Subject: [PATCH 6/9] Delete demo.html --- demo.html | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 demo.html diff --git a/demo.html b/demo.html deleted file mode 100644 index dbb9088..0000000 --- a/demo.html +++ /dev/null @@ -1,50 +0,0 @@ - - - - - jquery.simplyCountable.js demo - - - - - - - -

Simply Countable -
-
User Test 1 -

You have characters left.

-
How many characters are left?
-

-

-
-
-
-
User Test 2 -

You have used words.

-
How many words typed?
-

-

-
-
- - \ No newline at end of file From f0c3abf19c010e710d6475a565667650c9a4683a Mon Sep 17 00:00:00 2001 From: Eunice Date: Fri, 31 Oct 2014 04:03:48 -0400 Subject: [PATCH 7/9] Delete simplyCountable.jquery.json --- simplyCountable.jquery.json | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 simplyCountable.jquery.json diff --git a/simplyCountable.jquery.json b/simplyCountable.jquery.json deleted file mode 100644 index 48e1e27..0000000 --- a/simplyCountable.jquery.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "simplyCountable", - "version": "0.5.0", - "title": "jQuery Simply Countable", - "description": "jQuery plugin that provides a character counter for any text input or textarea.", - "author": { - "name": "Aaron Russell", - "url": "http://aaronrussell.co.uk" - }, - "keywords": [ - "forms", - "input", - "textarea", - "counter" - ], - "dependencies": { - "jquery": ">=1.4" - }, - "licenses": [ - { - "type": "MIT", - "url": "http://www.opensource.org/licenses/mit-license.php" - }, - { - "type": "GPL", - "url": "http://www.opensource.org/licenses/gpl-license.php" - } - ], - "homepage": "https://github.com/aaronrussell/jquery-simply-countable", - "bugs": "https://github.com/aaronrussell/jquery-simply-countable/issues" -} \ No newline at end of file From 5f8d5638a4dae1eaae4f22a3089f170c14dc38cd Mon Sep 17 00:00:00 2001 From: Eunice Date: Fri, 31 Oct 2014 04:04:23 -0400 Subject: [PATCH 8/9] Delete package.json --- package.json | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 package.json diff --git a/package.json b/package.json deleted file mode 100644 index 87c634f..0000000 --- a/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "react", - "private": "true", - "scripts": { - "test": "grunt" - }, - "devDependencies": { - "grunt": "^0.4.4", - "grunt-contrib-jshint": "^0.10.0", - "grunt-html-validation": "^0.1.15" - } -} From b22fdd219b041eceebaad5e049470ea22b3b69a9 Mon Sep 17 00:00:00 2001 From: Eunice Date: Fri, 31 Oct 2014 04:12:15 -0400 Subject: [PATCH 9/9] react assignment react assignment --- .gitignore | 2 ++ .travis.yml | 7 ------ Gruntfile.js | 45 --------------------------------- README.md | 18 ------------- demo.html | 50 ------------------------------------- index.html | 9 ------- jquery.simplyCountable.js | 14 ----------- package.json | 12 --------- simplyCountable.jquery.json | 31 ----------------------- 9 files changed, 2 insertions(+), 186 deletions(-) delete mode 100644 .travis.yml delete mode 100644 Gruntfile.js delete mode 100644 README.md delete mode 100644 demo.html delete mode 100644 index.html delete mode 100644 package.json delete mode 100644 simplyCountable.jquery.json diff --git a/.gitignore b/.gitignore index 3168ea5..3a49f7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules/ validation-* + +*.html diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b689349..0000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -language: node_js -node_js: -- '0.10' -branches: - only: - - /.*/ -before_install: npm install -g grunt-cli diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index df8bc7e..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,45 +0,0 @@ -module.exports = function(grunt) { - grunt.initConfig({ - jshint: { - files: { - src: [ - '**/.html', - '**/*.js', - // excluded files - '!node_modules/**/*', - '!vendor/**/*' - ] - }, - // http://www.jshint.com/docs/options/ - options: { - browser: true, - eqeqeq: true, - extract: 'auto', // http://bahmutov.calepin.co/linting-javascript-inside-html.html - forin: true, - freeze: true, - latedef: true, - maxdepth: 4, - maxparams: 3, - maxstatements: 10, - newcap: true - } - }, - validation: { - options: { - failHard: true, - reset: true - }, - files: { - src: [ - '**/*.html', - '!node_modules/**/*' - ] - } - } - }); - - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-html-validation'); - - grunt.registerTask('default', ['jshint', 'validation']); -}; diff --git a/README.md b/README.md deleted file mode 100644 index d40eb2f..0000000 --- a/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# "React" Assignment - -Create a learning resource that gives the user feedback – in other words, responds to the user's input/actions. Actions could include: - -* Clicking -* Typing -* Scrolling - -or lack of any of those things. Feel free to pick a new subject, or dive deeper with one you've already used. - -## Examples - -1. [Operation](http://en.wikipedia.org/wiki/Operation_(game)), which uses sound to inform the player they are doing something wrong. - - [![Operation](http://img.youtube.com/vi/_6MAkLJ79LE/0.jpg)](http://www.youtube.com/watch?v=_6MAkLJ79LE) - -1. An essay helper, where the user needs the their entry in a [`

-

- - -
-
User Test 2 -

You have used words.

-
How many words typed?
-

-

-
-
- - \ No newline at end of file diff --git a/index.html b/index.html deleted file mode 100644 index 3678415..0000000 --- a/index.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - So-and-so's React Assignment - - - YOUR PROJECT HERE - - diff --git a/jquery.simplyCountable.js b/jquery.simplyCountable.js index 7c1d577..a521802 100644 --- a/jquery.simplyCountable.js +++ b/jquery.simplyCountable.js @@ -1,16 +1,3 @@ -/* -* jQuery Simply Countable plugin -* Provides a character counter for any text input or textarea -* -* @version 0.4.2 -* @homepage http://github.com/aaronrussell/jquery-simply-countable/ -* @author Aaron Russell (http://www.aaronrussell.co.uk) -* -* Copyright (c) 2009-2010 Aaron Russell (aaron@gc4.co.uk) -* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) -* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. -*/ - (function($){ $.fn.simplyCountable = function(options){ @@ -54,7 +41,6 @@ var prefix = ''; if (options.thousandSeparator){ ct = ct.toString(); - // Handle large negative numbers if (ct.match(/^-/)) { ct = ct.substr(1); prefix = '-'; diff --git a/package.json b/package.json deleted file mode 100644 index 87c634f..0000000 --- a/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "react", - "private": "true", - "scripts": { - "test": "grunt" - }, - "devDependencies": { - "grunt": "^0.4.4", - "grunt-contrib-jshint": "^0.10.0", - "grunt-html-validation": "^0.1.15" - } -} diff --git a/simplyCountable.jquery.json b/simplyCountable.jquery.json deleted file mode 100644 index 48e1e27..0000000 --- a/simplyCountable.jquery.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "simplyCountable", - "version": "0.5.0", - "title": "jQuery Simply Countable", - "description": "jQuery plugin that provides a character counter for any text input or textarea.", - "author": { - "name": "Aaron Russell", - "url": "http://aaronrussell.co.uk" - }, - "keywords": [ - "forms", - "input", - "textarea", - "counter" - ], - "dependencies": { - "jquery": ">=1.4" - }, - "licenses": [ - { - "type": "MIT", - "url": "http://www.opensource.org/licenses/mit-license.php" - }, - { - "type": "GPL", - "url": "http://www.opensource.org/licenses/gpl-license.php" - } - ], - "homepage": "https://github.com/aaronrussell/jquery-simply-countable", - "bugs": "https://github.com/aaronrussell/jquery-simply-countable/issues" -} \ No newline at end of file