/** * jquery.postitall.js v1.0 * jQuery Post It All Plugin - released under MIT License * Author: Javi Filella * http://github.com/txusko/PostItAll * Copyright (c) 2015 Javi Filella * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * */ //Delay repetitive actions var delay = (function(){ var timer = 0; return function(callback, ms){ clearTimeout (timer); timer = setTimeout(callback, ms); }; })(); (function ($, $localStorage) { "use strict"; // Debug var debugging = true; // or true if (typeof console === "undefined") { console = { log: function () { return undefined; } }; } else if (!debugging || console.log === undefined) { console.log = function () { return undefined; }; } //Date Date.prototype.addDays = function(days) { var dat = new Date(this.valueOf()); dat.setDate(dat.getDate() + days); return dat; }; Date.prototype.addHours = function(hours) { var dat = new Date(this.valueOf()); dat.setTime(dat.getTime() + (hours*60*60*1000)); return dat; }; Date.prototype.addMinutes = function(minutes) { var dat = new Date(this.valueOf()); dat.setTime(dat.getTime() + (minutes*60*1000)); return dat; }; Date.prototype.addSeconds = function(seconds) { var dat = new Date(this.valueOf()); dat.setTime(dat.getTime() + (seconds*1000)); return dat; }; Date.prototype.toFormat = function (f) { var nm = this.getMonthName(); var nd = this.getDayName(); f = f.replace(/yyyy/g, this.getFullYear()); f = f.replace(/yy/g, String(this.getFullYear()).substr(2,2)); f = f.replace(/MMM/g, nm.substr(0,3).toUpperCase()); f = f.replace(/Mmm/g, nm.substr(0,3)); f = f.replace(/MM\*/g, nm.toUpperCase()); f = f.replace(/Mm\*/g, nm); f = f.replace(/mm/g, String(this.getMonth()+1).padLeft('0',2)); f = f.replace(/DDD/g, nd.substr(0,3).toUpperCase()); f = f.replace(/Ddd/g, nd.substr(0,3)); f = f.replace(/DD\*/g, nd.toUpperCase()); f = f.replace(/Dd\*/g, nd); f = f.replace(/dd/g, String(this.getDate()).padLeft('0',2)); f = f.replace(/d\*/g, this.getDate()); return f; }; Date.prototype.getMonthName = function () { return this.toLocaleString().replace(/[^a-z]/gi,''); }; //n.b. this is sooo not i18n safe :) Date.prototype.getDayName = function () { switch(this.getDay()) { //Se cambió el día de inglés a español case 0: return 'Domingo'; case 1: return 'Lunes'; case 2: return 'Martes'; case 3: return 'Miércoles'; case 4: return 'Jueves'; case 5: return 'Viernes'; case 6: return 'Sábado'; } }; String.prototype.padLeft = function (value, size) { var x = this; while (x.length < size) {x = value + x;} return x; }; // PLUGIN Public methods $.extend($.fn, { postitall: function (method, data, callback) { var t = new PostItAll(); var elem = $('.PIAeditable').find(this); //.filter(function(){ return !$(this).parents('#the_notes').length }) if(elem.length <= 0) elem = $(this); elem = elem.filter(function(){ return !$(this).parents('#the_lights').length }) switch (method) { // Destroy the control case 'destroy': elem.each(function (i, e) { if($(e).hasClass('PIApostit')) { t.destroy($(e)); } else if($(e).attr('PIA-original') !== undefined) { t.destroy($(e).parent().parent().parent().parent()); } }); return $(this); // Get/set options on the fly case 'options': // Setter //console.log('options', elem.length, data); var obj = undefined; elem.each(function (i, e) { if($(e).hasClass('PIApostit')) { if (data === undefined) { obj = $(e).data('PIA-options'); return false; } else { t.destroy($(e), false); var tempoptions = $(e).data('PIA-options') || {}; setTimeout(function() {$.PostItAll.new($.extend(true, tempoptions, data));}, 400); } } else if($(e).attr('PIA-original') !== undefined) { var oldObj = $(e).parent().parent().parent().parent(); if (data === undefined) { obj = oldObj.data('PIA-options'); return false; } else { t.destroy(oldObj, false); var tempoptions = oldObj.data('PIA-options') || {}; setTimeout(function() { $.PostItAll.new($.extend(true, tempoptions, data)); }, 400); } } }); if(obj !== undefined) { if($(obj).length == 1) return $(obj)[0]; return $(obj); } return $(this); // hide note/s case 'hide': elem.each(function (i, e) { if($(e).hasClass('PIApostit')) { t.hide($(e).data('PIA-id')); } else if($(e).attr('PIA-original') !== undefined) { t.hide($(e).parent().parent().parent().parent().data('PIA-id')); } }); return $(this); //show note/s case 'show': elem.each(function (i, e) { if($(e).hasClass('PIApostit')) { t.show($(e).data('PIA-id')); } else if($(e).attr('PIA-original') !== undefined) { t.show($(e).parent().parent().parent().parent().data('PIA-id')); } }); return $(this); // Save object case 'save': elem.each(function (i, e) { if($(e).hasClass('PIApostit')) { t.save($(e)); } else if($(e).attr('PIA-original') !== undefined) { t.save($(e).parent().parent().parent().parent()); } }); return $(this); // Initializes the control case 'new': default: var posX = 0, posY = 0, paso = false; if (method !== 'new') { data = method; method = "new"; } if(data === undefined || typeof data !== 'object') data = { }; //Position defined by the user if(!paso) { if(data.posX !== undefined) { posX = data.posX; paso = true; } if(data.posY !== undefined) { posY = data.posY; paso = true; } } //Check if initialized var initialized = false; $.each($(this).filter(function(){ return !$(this).parents((tab_activo=='tab_principal2'?'#the_notes':'#the_notes_sesion')).length }), function (i,e) { if($(e).attr('PIA-original') !== undefined) { initialized = true; return false; } }); if(!initialized) { //Create the element/s $.each($(this).filter(function(){ return !$(this).parents((tab_activo=='tab_principal2'?'#the_notes':'#the_notes_sesion')).length }), function (i,e) { //Position relative to the element if(!paso) { posX = $(this).offset().left; posY = $(this).offset().top; } $.extend(data, { posX: posX, posY: posY }, true); //console.log('create', i, e); $.PostItAll.new('', data, $(e), callback); }); } else { //Show previously initialized, show the notes $.PostItAll.show(); } return $(this); } } }); //Global vars : enable and disable features and change the notes behaviour $.fn.postitall.globals = { prefix : '#PIApostit_',//Id note prefixe filter : 'domain', //Options: domain, page, all savable : false, //Save postit in storage randomColor : true, //Random color in new postits toolbar : true, //Show or hide toolbar autoHideToolBar : true, //Animation efect on hover over postit shoing/hiding toolbar options removable : true, //Set removable feature on or off askOnDelete : true, //Confirmation before note remove draggable : true, //Set draggable feature on or off resizable : true, //Set resizable feature on or off editable : true, //Set contenteditable and enable changing note content changeoptions : true, //Set options feature on or off blocked : true, //Postit can not be modified hidden : true, //The note can be hidden minimized : true, //true = minimized, false = maximixed expand : false, //Expand note fixed : true, //Allow to fix the note in page addNew : true, //Create a new postit showInfo : true, //Show info icon (info tab) showMeta : true, //Show info icon (meta tab) pasteHtml : true, //Allow paste html in contenteditor htmlEditor : true, //Html editor (trumbowyg) autoPosition : true, //Automatic reposition of the notes when user resize screen addArrow : 'back', //Add arrow to notes : none, front, back, all askOnHide : true, //Show configuration hideUntil back-panel (getBackPanelHideUntil) hideUntil : null, //Note will be hidden since that datetime export : true //Note can be exported }; //Copy of the original global configuration $.fn.postitall.globalscopy = $.extend({}, $.fn.postitall.globals, true); //Note global vars : Properties, style, features and events of the note $.fn.postitall.defaults = { //Note properties id : "", //Note id created : Date.now(), //Creation date domain : window.location.origin, //Domain in the url page : window.location.pathname, //Page in the url osname : navigator.appVersion, //Browser informtion & OS name, content : '', //Content of the note (text or html) position : 'absolute', //Position relative, fixed or absolute posX : '100px', //x coordinate (from left) posY : '100px', //y coordinate (from top) right : '', //x coordinate (from right). This property invalidate posX height : 300, //Note total height width : 300, //Note total width minHeight : 200, //Note resizable min-width minWidth : 200, //Note resizable min-height oldPosition : {}, //Position when minimized/collapsed (internal use) //Config note style style : { tresd : true, //General style in 3d format backgroundcolor : '#FFFA3C', //Background color in new postits when randomColor = false textcolor : '#333333', //Text color textshadow : true, //Shadow in the text fontfamily : 'Open Sans', //Default font fontsize : 'medium', //Default font size arrow : 'none', //Default arrow : none, top, right, bottom, left }, //Enable / Disable features features : $.extend({}, $.fn.postitall.globals, true), //Note flags flags : { blocked : false, //If true, the note cannot be edited minimized : false, //true = Collapsed note / false = maximixed expand : false, //true = Expanded note / false = normal fixed : false, //Set position fixed highlight : false, //Higlight note hidden : false, //Hidden note }, //Attach the note to al html element attachedTo : { element : '', //Where to attach (string or object / '#idObject' or $('#idObject')) position : 'right', //Position relative to elemente : top, right, bottom or left fixed : true, //Fix note to element when resize screen arrow : true, //Show an arrow in the inverse position }, //Meta data meta: { 'Title': { 'type': 'input', 'maxlength': '20', 'value': '', 'placeholder': 'Note title' }, 'Category': { 'type': 'combo', 'value': '0', 'values': { '0': 'Select a category', '1': 'Personal', '2': 'Work', '3': 'Other' } }, 'Observations': { 'type': 'textarea', 'value': '', 'placeholder': 'Other considerations ...' } }, // Callbacks / Event Handlers onCreated: function(id, options, obj) { return undefined; }, //Triggered after note creation onChange: function (id) { return undefined; }, //Triggered on each change onSelect: function (id) { return undefined; }, //Triggered when note is clicked, dragged or resized onDblClick: function (id) { return undefined; }, //Triggered on double click onRelease: function (id) { return undefined; }, //Triggered on the end of dragging and resizing of a note onDelete: function (id) { return undefined; } //Triggered when a note is deleted }; //Copy of the original note configuration $.fn.postitall.defaultscopy = $.extend({}, $.fn.postitall.defaults, true); $.fn.postitall.defaultscopy.style = $.extend({}, $.fn.postitall.defaults.style, true); $.fn.postitall.defaultscopy.features = $.extend({}, $.fn.postitall.defaults.features, true); $.fn.postitall.defaultscopy.flags = $.extend({}, $.fn.postitall.defaults.flags, true); $.fn.postitall.defaultscopy.attachedTo = $.extend({}, $.fn.postitall.defaults.attachedTo, true); //Global functions jQuery.PostItAll = { //Initialize environement __initialize : function() { //The notes if($('#the_notes').length <= 0) { $('
').appendTo($('body')); } if($('#the_notes_sesion').length <= 0) { $('
').appendTo($('body')); } //The ligths if($('#the_lights').length <= 0) { $('
').appendTo($('body')); $('#the_lights').click(function() { var note = new PostItAll(); note.switchOnLights(); }); } //Upload note if($('#the_imports').length <= 0) { //Import file var importFile = function() { //Check support if (!window.FileReader) { console.log('Browser do not support FileReader.') return; } //Get file var input = $('#idImportFile').get(0); if (input.files.length) { //Get text var textFile = input.files[0]; if(textFile.size > 0 && textFile.type == "text/plain") { //Create a new FileReader & read content var reader = new FileReader(); reader.readAsText(textFile); $(reader).on('load', function(e) { //Text readed var file = e.target.result,results; if (file && file.length) { //Check object var obj = JSON.parse(file); if(typeof obj === 'object') { //create new note var newNote = function(obj) { delete obj.id; //reset id //TODO : reset domain&page or redirect? delete obj.domain; delete obj.page; $.PostItAll.new(obj); } if(obj.id !== undefined) { //One note newNote(obj); } else if($(obj).length > 0) { //Various notes $(obj).each(function(n1,obj2) { if(obj2.id !== undefined) { setTimeout(function() { newNote(obj2); }, 250 + ( n1 * 250 )); } }); } else { alert('No hay notas a importar'); } } else { alert('Invalid file content'); } } }); } else { alert('The file is empty or is not a text file.'); } } else { alert('Please upload a file before continuing.') } }; //The imports var updString = $("
", { 'the_imports': '', 'style' : 'display:none;' }); //Input fle var impFile = $('', { id : "idImportFile", type : "file", name : "files" }).on("change", function () { $('#idImportUpload').click(); $('#idImportFile').val(""); }); //Input button var impBut = $('