Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

stuff

  • Loading branch information...
commit 7443f5741f7b96a4eeee7ba7b75995275d7ad502 1 parent 090b3bd
Christof Haemmerle authored
Showing with 46 additions and 37 deletions.
  1. +5 −1 index.html
  2. +1 −1  tumblertags.css
  3. +40 −35 tumblertags.js
6 index.html
View
@@ -34,7 +34,11 @@
</div>
</div>
-
+ <!-- Tags -->
+ <div class="tag-editor">
+ <label>Tags</label>
+ <input name="tags" type="text" value="music,fun,journal,the guy" />
+ </div>
</body>
</html>
2  tumblertags.css
View
@@ -28,7 +28,7 @@ input:focus {
background: none;
padding: .2em 0;
width: 50px;
- float: left;
+/* float: left;*/
}
.tag-editor .tags-container {
75 tumblertags.js
View
@@ -12,40 +12,45 @@
(function ($) {
- $.fn.tumblertags = function () {
- return this.each(function () {
- var $tagEditor = $(this);
- var $tagContainer = $(this).find('.tags-container');
- var $inputField = $tagContainer.find('input')
-
- // conlick focus input field
- $tagContainer.click(function(){
- $inputField.focus();
- $(this).addClass('focus');
- });
-
- // remove the focus when input blur is fired
- $inputField.blur(function(){
- $tagContainer.removeClass('focus');
- });
-
- // when pressing the returnkey, wraping the text of input field in a span and prepend it to the input field.
- $inputField.keyup(function(e, keyCode){
- keyCode = keyCode || e.keyCode;
- if (keyCode == 8 && $inputField.val() == '') {
- $tagContainer.find('span:last').remove();
- };
- if (keyCode == 13 && $inputField.val() != '') {
- $newTag = $('<span class="tag">' + $inputField.val() + '<a href="#" title="remove tag">x</a></span>');
- $inputField.val('');
- $newTag.insertBefore($inputField).find('a').click(function() {
- $(this).parent().remove();
- });
- return false; // if contained in a form hitting return would submit the form, we want to avoid that.
- };
- });
-
- });
- };
+ $.fn.tumblertags = function () {
+
+ return this.each(function () {
+
+ var $tagEditor = $(this).append('<div class="visualClear"></div>'),
+ $inputField = $tagEditor.find('input'),
+ $tagContainer = $inputField.wrap('<div class=".tags-container"></div>'),
+ tags = $inputField;
+
+ console.log("tags: ", tags);
+
+ // conlick focus input field
+ $tagContainer.click(function(){
+ $inputField.focus();
+ $(this).addClass('focus');
+ });
+
+ // remove the focus when input blur is fired
+ $inputField.blur(function(){
+ $tagContainer.removeClass('focus');
+ });
+
+ // when pressing the returnkey, wraping the text of input field in a span and prepend it to the input field.
+ $inputField.keyup(function(e, keyCode){
+ keyCode = keyCode || e.keyCode;
+ if (keyCode == 8 && $inputField.val() == '') {
+ $tagContainer.find('span:last').remove();
+ };
+ if (keyCode == 13 && $inputField.val() != '') {
+ $newTag = $('<span class="tag">' + $inputField.val() + '<a href="#" title="remove tag">x</a></span>');
+ $inputField.val('');
+ $newTag.insertBefore($inputField).find('a').click(function() {
+ $(this).parent().remove();
+ });
+ return false; // if contained in a form hitting return would submit the form, we want to avoid that.
+ };
+ });
+
+ });
+ };
})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.