|
| 1 | +/** |
| 2 | + * QuickNote - jQuery plugin that lets you add quick note or todo note. |
| 3 | + * This plugin is useful for admin panel dashboard. |
| 4 | + * |
| 5 | + * Copyright 2014 Pantuts |
| 6 | + * Licensed under GNU GPLv3 |
| 7 | + * https://github.com/pantuts |
| 8 | + * http://pantuts.com |
| 9 | + */ |
| 10 | + |
| 11 | +;(function($, window, document, undefined) { |
| 12 | + |
| 13 | + 'use strict'; |
| 14 | + |
| 15 | + var QuickNote = function(el, options) { |
| 16 | + this.el = el; |
| 17 | + this.$el = $(el); |
| 18 | + this.options = options; |
| 19 | + }; |
| 20 | + |
| 21 | + QuickNote.prototype = { |
| 22 | + defaults: { |
| 23 | + theme: 'dark', |
| 24 | + pos: 'right' |
| 25 | + }, |
| 26 | + init: function() { |
| 27 | + this.config = $.extend({}, this.defaults, this.options); |
| 28 | + this.appendElem(); |
| 29 | + this.completeNote(); |
| 30 | + }, |
| 31 | + appendElem: function() { |
| 32 | + // THEME |
| 33 | + if (this.config.theme == 'light') { |
| 34 | + this.$el.addClass('qn_container_light').addClass('qn_container'); |
| 35 | + } else if (this.config.theme == 'dark') { |
| 36 | + this.$el.addClass('qn_container'); |
| 37 | + } else { |
| 38 | + console.log('Error: Theme >> ' + this.config.theme + ' not found.'); |
| 39 | + // set default |
| 40 | + this.$el.addClass('qn_container'); |
| 41 | + } |
| 42 | + |
| 43 | + // POSITION |
| 44 | + if (this.config.pos == 'left') { |
| 45 | + this.$el.css({ 'left':'0', 'bottom':'0', 'margin-left':'5px' }); |
| 46 | + } else if (this.config.pos == 'right') { |
| 47 | + } else { |
| 48 | + console.log('Error: Position >> ' + this.config.pos + ' not found.'); |
| 49 | + } |
| 50 | + |
| 51 | + var showHide = '<div id="qn_sh"><span>Show/Hide</span></div>'; |
| 52 | + var divNotes = '<div id="notes"></div>'; |
| 53 | + var notesInp = '<p><input type="text" name="qn_input" maxlength="200" placeholder="Your notes...[Click to close]"></p>'; |
| 54 | + $(showHide).appendTo(this.$el); |
| 55 | + $(divNotes).appendTo(this.$el); |
| 56 | + $(notesInp).appendTo(this.$el.find('#notes')); |
| 57 | + }, |
| 58 | + completeNote: function() { |
| 59 | + // i USED FOR NOTES ID |
| 60 | + var i = 0; |
| 61 | + $('.qn_container').on('keypress', '#notes input', function(e) { |
| 62 | + // RETURN KEY PRESSED |
| 63 | + if (e.which == 13 || e.keyCode == 13) { |
| 64 | + var notesInpVal = $('#notes input').val(); |
| 65 | + if (notesInpVal) { |
| 66 | + $('<span class="quicknote" id="qn_' + i + '"></span>').css({ display: 'table' }).stop().fadeIn('fast').appendTo('.qn_container #notes').text(notesInpVal); |
| 67 | + $('.qn_container #notes input').val(''); |
| 68 | + i++; |
| 69 | + } else { |
| 70 | + console.log('Empty note!'); |
| 71 | + } |
| 72 | + } |
| 73 | + }); |
| 74 | + |
| 75 | + // SHOW AND HIDE |
| 76 | + $('.qn_container').on('click', '#qn_sh span', function(){ |
| 77 | + $('.qn_container #notes').slideToggle(100); |
| 78 | + }); |
| 79 | + |
| 80 | + // CLICK TO CLOSE NOTES |
| 81 | + $('.qn_container').on('click', '#notes .quicknote', function(){ |
| 82 | + $(this).each(function(){ |
| 83 | + $(this).stop().fadeOut('fast', function() { |
| 84 | + $(this).remove(); |
| 85 | + }); |
| 86 | + }); |
| 87 | + }); |
| 88 | + } |
| 89 | + }; |
| 90 | + |
| 91 | + $.fn.quicknote = function(options) { |
| 92 | + return this.each(function() { |
| 93 | + new QuickNote(this, options).init(); |
| 94 | + }); |
| 95 | + }; |
| 96 | + |
| 97 | +})(jQuery, window, document); |
0 commit comments