').css({visibility: 'hidden', width: 94, overflow: 'scroll'}).appendTo('body');
var widthWithScroll = $('
').css({width: '100%'}).appendTo(outer).outerWidth();
outer.remove();
return 100 - widthWithScroll;
}
var updateNote = function() {
if($($.fn.postitall.globals.prefix + data.id).length > 0) {
$($.fn.postitall.globals.prefix + data.id).animate({
'top': data.posY,
'left': data.posX
}, 200, function() {
if(data.style.arrow != "none") {
//t.hideArrow(data.id, function() {
t.showArrow(data.id, data);
//});
}
});
}
}
switch(pos1) {
case 'top':
data.posY = position.top - noteHeight - 20;
if(pos2 == "left") {
data.posX = (position.left + (objWidth * 0.1)) - (data.width / 2);
} else if(pos2 == "right") {
data.posX = (position.left + (objWidth - (objWidth * 0.1))) - (data.width / 2);
} else {
data.posX = (position.left + (objWidth / 2)) - (data.width / 2);
}
if(data.attachedTo.arrow && data.style.arrow != "bottom") {
data.style.arrow = "bottom";
t.hideArrow(data.id);
}
break;
case 'right':
default:
data.posX = position.left + objWidth + 20;
if(pos2 == "top") {
data.posY = (position.top + (objHeight * 0.1)) - (data.height / 2);
} else if(pos2 == "bottom") {
data.posY = (position.top + (objHeight - (objHeight * 0.1))) - (data.height / 2);
} else {
data.posY = (position.top + (objHeight / 2)) - (data.height / 2);
}
if(data.attachedTo.arrow && data.style.arrow != "left") {
data.style.arrow = "left";
t.hideArrow(data.id);
}
break;
case 'bottom':
data.posY = position.top + objHeight + 20;
if(pos2 == "left") {
data.posX = (position.left + (objWidth * 0.1)) - (data.width / 2);
} else if(pos2 == "right") {
data.posX = (position.left + (objWidth - (objWidth * 0.1))) - (data.width / 2);
} else {
data.posX = (position.left + (objWidth / 2)) - (data.width / 2);
}
if(data.attachedTo.arrow && data.style.arrow != "top") {
data.style.arrow = "top";
t.hideArrow(data.id);
}
break;
case 'left':
data.posX = position.left - noteWidth - 20;
if(pos2 == "top") {
data.posY = (position.top + (objHeight * 0.1)) - (data.height / 2);
} else if(pos2 == "bottom") {
data.posY = (position.top + (objHeight - (objHeight * 0.1))) - (data.height / 2);
} else {
data.posY = (position.top + (objHeight / 2)) - (data.height / 2);
}
if(data.attachedTo.arrow && data.style.arrow != "right") {
data.style.arrow = "right";
t.hideArrow(data.id);
}
break;
}
if(pos1 === "left" || pos1 === "right") {
fixHorizontal(function() {
fixVertical();
});
} else if(pos1 === "top" || pos1 === "bottom") {
fixVertical(function() {
fixHorizontal();
});
}
if(data.attachedTo.fixed === undefined)
data.attachedTo.fixed = true;
setTimeout(function() { updateNote(); }, 200);
},
//Save object
save : function(obj, callback) {
var options = obj.data('PIA-options');
if(!$.fn.postitall.globals.savable && !options.features.savable)
return;
//console.log('save', options);
options.features.savable = true;
this.saveOptions(options, callback);
},
//Save options
saveOptions : function(options, callback) {
if(options === undefined)
options = this.options;
//console.log('saveOptions', options.posX, options.posY, options.width, options.height);
if ($.fn.postitall.globals.savable || options.features.savable) {
//console.log(options);
storageManager.add(options, function(error) {
if(error != "") {
if(callback != null) callback(error);
else alert('Error saving options: ' + error);
} else {
if(callback != null) callback();
}
});
}
options.onChange($.fn.postitall.globals.prefix + options.id);
},
//Destroy and remove
destroy : function(obj, callOnDelete) {
//Swith on lights
//this.switchOnLights();
//this.disableKeyboardNav();
//console.log(obj);
if(obj === undefined)
obj = $($.fn.postitall.globals.prefix + this.options.id);
if(callOnDelete === undefined)
callOnDelete = true;
var options = obj.data('PIA-options');
//console.log(this,options, obj);
var id = options.id;
//console.log('destroy', id, $.fn.postitall.globals.savable, options.features.savable);
//Remove from localstorage
if ($.fn.postitall.globals.savable || options.features.savable) {
if(options.features.savable) {
storageManager.remove(id);
options.onChange($.fn.postitall.globals.prefix + id);
} else {
storageManager.get(id, function(varvalue) {
if(varvalue != null && varvalue != "")
storageManager.remove(id);
options.onChange($.fn.postitall.globals.prefix + id);
});
}
}
//Destroy object
this.remove(options);
//Event handler on delete
if(callOnDelete) {
options.onDelete($.fn.postitall.globals.prefix + id);
}
},
//Hide note
remove : function(options) {
//hide object
var id = options.id;
//console.log('remove', id);
$($.fn.postitall.globals.prefix + id).removeData('PIA-id')
.removeData('PIA-initialized')
.removeData('PIA-settings')
.animate({
opacity: 0,
height: 0
}, function() {
$(this).remove();
});
/*.hide("slow", function () {
$(this).remove();
});*/
if(this.length <= 0)
$(window).off('resize');
},
hide : function(id) {
//hide object
if($($.fn.postitall.globals.prefix + id).length) {
var options = $($.fn.postitall.globals.prefix + id).data('PIA-options');
options.flags.hidden = true;
$($.fn.postitall.globals.prefix + id).slideUp();
this.saveOptions(options);
}
},
show : function(id) {
//show object
if($($.fn.postitall.globals.prefix + id).length) {
var options = $($.fn.postitall.globals.prefix + id).data('PIA-options');
options.flags.hidden = false;
options.features.hideUntil = null;
$($.fn.postitall.globals.prefix + id).slideDown();
this.saveOptions(options);
}
},
//Show the note in a specific date
showAgain : function(index, dat) {
var t = this;
var setToHappen = function(fn, date){
var now = new Date().getTime();
var diff = date.getTime() - now;
return setTimeout(fn, diff);
};
var dateFinish = new Date(dat);
if(dateFinish > Date.now()) {
console.log('show again on ' + dateFinish, Date.now() );
setToHappen(function() {
t.show(index);
}, dateFinish);
} else {
t.show(index);
}
},
//When user change arrow
arrowChangeOption : function(value) {
var index = this.options.id;
var options = this.options;
if($.fn.postitall.globals.addArrow == "none" && options.features == "none") {
return;
}
//console.log('arrowChangeOption', options.style.arrow, value);
//Get new position
if(options.style.arrow == value || value == 'none') {
//If this position is the same as before, remove arrow and show selectors
options.style.arrow = 'none';
$('.selectedArrow_'+index).show();
$('.selectedArrow_'+index).find('span').show();
} else {
//Set arrow and hide selectors
options.style.arrow = value;
$('.selectedArrow_'+index).hide();
}
//Change options arrow select
$('#idAddArrow_'+index).val(options.style.arrow);
this.hideArrow(index);
this.showArrow(index, options);
this.saveOptions(options);
return options;
},
//Hide arrow & icons
hideArrow : function(ind, callback) {
var index = this.options.id;
if(ind !== undefined)
index = ind;
//Remove previous arrow
$($.fn.postitall.globals.prefix + index).removeClass('arrow_box_top arrow_box_right arrow_box_bottom arrow_box_left', 1000, "easeInElastic");
$($.fn.postitall.globals.prefix + index).find('.icon_box').hide();
if(!$.ui) $($.fn.postitall.globals.prefix + index).css('overflow', 'hidden').css('resize', 'both');
//console.log('hide');
if(callback !== undefined) setTimeout(function() { callback(); }, 100);
},
//Show arrow and icons
showArrow : function(ind, opt) {
var index = this.options.id;
if(ind !== undefined)
index = ind;
var options = this.options;
if(opt !== undefined)
options = opt;
//delay(function() {
//Add arrow
//console.log(options.style.arrow, ($.fn.postitall.globals.prefix + index));
switch(options.style.arrow) {
case 'top':
$($.fn.postitall.globals.prefix + index).addClass('arrow_box_top', 1000, "easeInElastic").css('overflow', '').css('resize', '');
break;
case 'right':
$($.fn.postitall.globals.prefix + index).addClass('arrow_box_right', 1000, "easeInElastic").css('overflow', '').css('resize', '');
break;
case 'bottom':
$($.fn.postitall.globals.prefix + index).addClass('arrow_box_bottom', 1000, "easeInElastic").css('overflow', '').css('resize', '');
break;
case 'left':
$($.fn.postitall.globals.prefix + index).addClass('arrow_box_left', 1000, "easeInElastic").css('overflow', '').css('resize', '');
break;
}
//console.log('options.style.arrow',options.style.arrow);
if(options.style.arrow == 'none')
$($.fn.postitall.globals.prefix + index).find('.icon_box').show();
var icon = $($.fn.postitall.globals.prefix + index).find('div[data-value="'+options.style.arrow+'"]');
icon.show();
icon.find('span').hide();
//console.log('show');
//}, 250);
},
//Autoresize note
autoresize : function() {
var t = this;
var id = this.options.id;
var options = this.options;
var obj = $($.fn.postitall.globals.prefix + id);
if(options.flags.minimized || options.flags.expand)
return;
var toolBarHeight = parseInt(obj.find('.PIAtoolbar').height(), 10);
var contentHeight = parseInt(obj.find('.PIAeditable').height(), 10) + toolBarHeight,
posX = obj.css('left'),
posY = obj.css('top'),
divWidth = parseInt(obj.css('width'), 10),//parseInt(obj.width(), 10) + parseInt(obj.css('padding-left'),10) + parseInt(obj.css('padding-right'),10) + 2,
divHeight = parseInt(obj.css('height'), 10),
minDivHeight = options.minHeight;
var htmlEditorBarHeight = parseInt(obj.find('.trumbowyg-button-pane').height(), 10);
if(isNaN(htmlEditorBarHeight) || htmlEditorBarHeight <= 30) {
htmlEditorBarHeight = 35;
}
//JESM-ENE2021
var contenedorTexto = obj.find('.PIAeditable');
if(contentHeight > divHeight - 30) {
//JESM-ENE2021 divHeight = contentHeight + htmlEditorBarHeight;
} else if(contentHeight > options.minHeight) {
//Comment this line if we want to preserve user height
//JESM-ENE2021 divHeight = contentHeight + htmlEditorBarHeight;
}
//console.log('newHeight',divHeight);
options.height = divHeight;
//obj.animate({ 'height': divHeight }, 250);
obj.css('height', divHeight);
//console.log('auto', divWidth);
options.width = divWidth;
//JESM-ENE2021
if (contenedorTexto && contenedorTexto.length > 0){
contenedorTexto.css('width', divWidth);
contenedorTexto.css('height', divHeight-50);
}
if(!$( "#pia_editable_" + id ).is(':focus')) {
if(options.attachedTo.element !== "" && options.attachedTo.fixed)
t.attachedTo();
}
},
//Get next note Id
getIndex : function(savable, callback) {
if(!savable) {
callback(this.guid());
return;
}
var len = 0;
var content = "";
var paso = false;
storageManager.getlength(function(len) {
//console.log('getIndex.len', len);
var loadedItems = $('.PIApostit').length;
var items = len + loadedItems + 1;
//console.log('getIndex.items', items);
for(var i = 1; i <= items; i++) {
(function(i) {
storageManager.get(i, function(content) {
//console.log('getIndex.get', paso, i, content);
if(!paso && (content == null || content == "") && $( "#idPostIt_" + i ).length <= 0) {
//console.log('nou index', i);
paso = true;
}
if(callback != null && (paso || i >= items)) {
callback(i);
callback = null;
}
});
})(i);
}
});
},
// Set options
setOptions : function(opt, save) {
var t = this;
if (typeof opt !== 'object') {
opt = {};
}
if (save === undefined) {
save = false;
}
t.options = $.extend(t.options, opt);
/*jslint unparam: true*/
$.each(['onChange', 'onSelect', 'onRelease', 'onDblClick'], function (i, e) {
if (typeof t.options[e] !== 'function') {
t.options[e] = function () { return undefined; };
}
});
/*jslint unparam: false*/
if (save) {
//console.log('setOptions save', t.options);
this.saveOptions(t.options);
}
},
// Get user selection text on page
getSelectedText : function() {
var text = "";
if (window.getSelection) {
text = window.getSelection();
} else if (document.selection) {
text = document.selection.createRange().text;
}
return text;
},
// Get user selection html on page
getSelectedHtml : function() {
var html = "";
if (typeof window.getSelection != "undefined") {
var sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
html = container.innerHTML;
}
} else if (typeof document.selection != "undefined") {
if (document.selection.type == "Text") {
html = document.selection.createRange().htmlText;
}
}
return html;
},
//Recover client OS name
getOSName : function() {
var OSName="Unknown OS";
var browserNav = this.options.osname;
if (browserNav.indexOf("Win")!=-1) OSName="Windows";
if (browserNav.indexOf("Mac")!=-1) OSName="MacOS";
if (browserNav.indexOf("X11")!=-1) OSName="UNIX";
if (browserNav.indexOf("Linux")!=-1) OSName="Linux";
return OSName;
},
//flip cover to back
switchBackNoteOn : function(flipClass) {
var id = this.options.id;
$('#the_lights').data('highlightedId', id);
this.enableKeyboardNav();
$('#idPostIt_' + id + ' > .PIAback').css('visibility', 'visible');
$($.fn.postitall.globals.prefix + id).addClass('PIAflip ' + flipClass, function () {
$($.fn.postitall.globals.prefix + id + ' > .PIAfront').css('visibility', 'hidden');
$($.fn.postitall.globals.prefix + id + ' > .ui-resizable-handle').css('visibility', 'hidden');
});
if($.fn.postitall.globals.resizable && $.ui) $($.fn.postitall.globals.prefix + id).resizable("disable");
if($.fn.postitall.globals.draggable && $.ui) {
setTimeout(function() {
$($.fn.postitall.globals.prefix + id).draggable({disabled: true});
}, 500);
}
//$(this).parent().parent().parent().parent().addClass('PIAflip');
},
//flip back to cover
switchBackNoteOff : function(flipClass) {
var id = this.options.id;
$('#the_lights_close').click();
this.disableKeyboardNav();
$('#idPostIt_' + id + ' > .PIAfront').css('visibility', 'visible');
$($.fn.postitall.globals.prefix + id).removeClass('PIAflip ' + flipClass, function () {
$($.fn.postitall.globals.prefix + id + ' > .PIAback').css('visibility', 'hidden');
$($.fn.postitall.globals.prefix + id + ' > .ui-resizable-handle').css('visibility', '');
});
if($.fn.postitall.globals.resizable && $.ui) $($.fn.postitall.globals.prefix + id).resizable("enable");
if($.fn.postitall.globals.draggable && $.ui) {
setTimeout(function() {
//Enable draggable
$($.fn.postitall.globals.prefix + id).draggable({disabled: false});
//Show back-date
$('#idDateBackToolbar_' + id).show();
}, 500);
}
},
//add transparency to note
switchTrasparentNoteOn : function() {
var id = this.options.id;
var options = this.options;
var components = this.getRGBComponents(options.style.backgroundcolor);
//$($.fn.postitall.globals.prefix + id).css('background', 'rgb('+components.R+', '+components.G+', '+components.B+')');
$($.fn.postitall.globals.prefix + id).css('background-color', 'rgba('+components.R+', '+components.G+', '+components.B+', 0.8)');
},
//remove transparency to note
switchTrasparentNoteOff : function() {
var id = this.options.id;
var options = this.options;
var components = this.getRGBComponents(options.style.backgroundcolor);
//$($.fn.postitall.globals.prefix + id).css('background', 'rgb('+components.R+', '+components.G+', '+components.B+')');
$($.fn.postitall.globals.prefix + id).css('background-color', 'rgba('+components.R+', '+components.G+', '+components.B+', 1)');
},
//Switch off lights and highlight note
switchOffLights : function() {
var t = this;
var id = t.options.id;
if(id !== undefined) {
$($.fn.postitall.globals.prefix + id).css({
'z-index': 999999,
'border': '1px solid rgb(236, 236, 0)',
'box-shadow': 'rgb(192, 195, 155) 1px 1px 10px 3px',
});
}
setTimeout(function() {
$("#the_lights").fadeTo("fast", 0.6, function() {
$("#the_lights").css('display','block');
$("#the_lights").css({'height':($(document).height())+'px'});
$("#the_lights").css({'width':($(document).width())+'px'});
$("#the_lights").data('highlightedId', id);
// lock scroll position, but retain settings for later
var scrollPosition = [
self.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,
self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
];
$('html').data('scroll-position', scrollPosition);
$('html').data('previous-overflow', $('html').css('overflow'));
$('html').css('overflow', 'hidden');
$(window).on('resize', $.proxy(t.resizeAction, t));
window.scrollTo(scrollPosition[0], scrollPosition[1]);
});
}, 500);
},
//Switch lights on & remove highlighted note
switchOnLights : function() {
var id = $("#the_lights").data('highlightedId');
var options = $($.fn.postitall.globals.prefix + id).data('PIA-options');
var t = this;
if(id !== "" && options !== null && options !== undefined) {
$("#the_lights").data('highlightedId', '');
$($.fn.postitall.globals.prefix + id).css({
'z-index': 999995,
'border': '1px solid ' + $($.fn.postitall.globals.prefix + id).css('background-color'),
'box-shadow': '',
});
if(options.flags.expand) {
$('#pia_expand_'+id).click();
} else {
$('#pia_close_'+id).click();
}
}
if($("#the_lights").css('display') != "none") {
$("#the_lights").css('display','block');
$("#the_lights").fadeTo("slow",0, function() {
$("#the_lights").css('display','none');
});
// un-lock scroll position
var scrollPosition = $('html').data('scroll-position');
if(scrollPosition != undefined) {
//console.log('unlock', scrollPosition);
var tmpOvf = $('html').data('previous-overflow');
$('html').css('overflow', (tmpOvf != "hidden") ? tmpOvf : "visible" );
window.scrollTo(scrollPosition[0], scrollPosition[1]);
}
$(window).off('resize');
//Set on resize action
if($.fn.postitall.globals.autoPosition) // && options.features.autoPosition)
$(window).on('resize', $.proxy(t.relativePosition, t));
}
},
//On resize when lights are off
switchOffLightsResize : function() {
$("#the_lights").css({'height':($(document).height())+'px'});
},
//Enable keyboard actions
enableKeyboardNav : function(callback) {
//console.log('enableKeyboardNav');
this.callback = callback;
$(document).on('keyup.keyboard', $.proxy(this.keyboardAction, this));
},
//Disable keybord actions
disableKeyboardNav : function() {
//console.log('disableKeyboardNav');
$(document).off('keyup.keyboard');
},
//Keyboard actions
keyboardAction : function(event) {
//console.log('keyboardAction', event);
var KEYCODE_ESC = 27;
var keycode = event.keyCode;
var key = String.fromCharCode(keycode).toLowerCase();
//On keypress ESC
if (keycode === KEYCODE_ESC) { // || key.match(/x|o|c/)) {
//console.log('key press ESC');
if(this.callback != undefined) this.callback();
this.switchOnLights();
this.disableKeyboardNav();
}
},
//Resize expanded note when screen size changes
resizeAction : function(event) {
var t = this;
delay(function(){
//console.log('resizeAction', t.options.id);
//Lights switched off
var highlightedId = $("#the_lights").data('highlightedId');
if(highlightedId !== undefined && highlightedId !== ""){
t.switchOffLightsResize();
var options = $($.fn.postitall.globals.prefix + highlightedId).data('PIA-options');
if(options.flags.expand) {
$($.fn.postitall.globals.prefix + highlightedId).css({
top:'10px'
}).animate({
'height': $(window).height() - 30,
'width': $(window).width() - 30
});
}
}
}, 500);
},
//On screen resize, notes will preserve relative position to new width screen
relativePosition : function(event) {
var t = this;
if(!$.fn.postitall.globals.autoPosition || !t.options.features.autoPosition) {
$(window).off('resize');
return;
}
var obj, options;
delay(function(){
$('.PIApostit').each(function(i,e) {
obj = $($.fn.postitall.globals.prefix + $(e).data('PIA-id'));
options = $($.fn.postitall.globals.prefix + $(e).data('PIA-id')).data('PIA-options');
//console.log(i,options,obj);
if(options !== undefined && options.attachedTo.element !== undefined && options.attachedTo.element !== "") {
//Attached elements
if(options.attachedTo.fixed !== undefined && options.attachedTo.fixed)
t.attachedTo(options);
} else {
//Floating elements
//console.log('new pos for note ', i, e);
var noteLoc = obj.offset();
var screenLoc = { 'height': $(window).height(), 'width': $(window).width() };
var top = noteLoc.top;
var left = noteLoc.left;
var width = parseInt($(e).css('width'), 10) + parseInt($(e).css('padding-left'), 10) + parseInt($(e).css('padding-right'), 10);
var height = parseInt($(e).css('height'), 10) + parseInt($(e).css('padding-top'), 10) + parseInt($(e).css('padding-bottom'), 10);
var x1 = left, x2 = (left + width), y1 = top, y2 = (top + height);
var relTop = (y1 / screenLoc.height) * 100;
var relLeft = (x1 / screenLoc.width) * 100;
var relWidth = ((x2 - x1) / screenLoc.width) * 100;
var relHeight = ((y2 - y1) / screenLoc.height) * 100;
$(e).css({
//'top': relTop + "%",
'left': relLeft + "%",
//'width': relWidth + "%",
//'height': relHeight + "%"
});
options.posX = obj.offset().left;
}
//Save
obj.data('PIA-options', options);
//console.log('options', options);
});
//$.PostItAll.save();
}, 100);
},
//Save current note position in options.oldPosition
saveOldPosition : function() {
var obj = $($.fn.postitall.globals.prefix + this.options.id);
var leftMinimized = obj.css('left');
if(this.options.oldPosition !== undefined && this.options.oldPosition.leftMinimized !== undefined)
leftMinimized = this.options.oldPosition.leftMinimized;
var propCss = {
'position': obj.css('position'),
'left': obj.css('left'),
'top': obj.css('top'),
'height': obj.css('height'),
'width': obj.css('width'),
'leftMinimized': leftMinimized,
};
this.options.oldPosition = propCss;
//console.log('saveOldPosition', this.options.oldPosition);
this.setOptions(this.options, true);
},
//Scroll to note position
scrollToNotePosition : function(tmpTop, tmpHeight, tmpLeft, tmpWidth, callback) {
var scrollTop1 = self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
var scrollBottom1 = scrollTop1 + $(window).height();
var scrollTop2 = parseInt(tmpTop, 10);
var scrollBottom2 = scrollTop2 + parseInt(tmpHeight,10);
var scrollLeft1 = self.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft;
var scrollRight1 = scrollLeft1 + $(window).width();
var scrollLeft2 = parseInt(tmpLeft, 10);
var scrollRight2 = scrollLeft2 + parseInt(tmpWidth,10);
//console.log(scrollTop2,scrollTop1,scrollBottom2,scrollBottom1);
if(scrollTop2 > scrollTop1 && scrollBottom2 < scrollBottom1 && scrollLeft2 > scrollLeft1 && scrollRight2 < scrollRight1) {
if(callback !== undefined) callback();
} else {
$('html, body').animate({
scrollTop: scrollTop2 - parseInt(tmpHeight,10),
scrollLeft: scrollLeft2 - parseInt(tmpWidth,10)
}, 400);
setTimeout(function() {
if(callback !== undefined) callback();
}, 500);
}
},
//Restore note with options.oldPosition
restoreOldPosition : function(scrollToNote, callback) {
if(scrollToNote === undefined)
scrollToNote = false;
var t = this;
var options = t.options;
var id = options.id;
var showNote = function() {
if(options.oldPosition.position == "absolute") {
$($.fn.postitall.globals.prefix + id).css({
'top': parseInt($($.fn.postitall.globals.prefix + id).css('top'), 10) + $(document).scrollTop()
});
} else {
$($.fn.postitall.globals.prefix + id).css({
'top': $($.fn.postitall.globals.prefix + id).css('top'),
});
}
$($.fn.postitall.globals.prefix + id).css({
'position': 'absolute',
'bottom': 'auto',
});
setTimeout(function(){
$($.fn.postitall.globals.prefix + id).animate({
'top': options.oldPosition.top,
'left': options.oldPosition.left,
'width': options.oldPosition.width,
'height': options.oldPosition.height,
}, 500, function() {
t.showArrow(id, options);
$(this).find( ".PIAeditable" ).css('height', 'auto');
t.autoresize();
//animate resize
if(options.flags.blocked) {
options.flags.blocked = false;
t.blockNote();
} else {
t.hoverOptions(id, true);
}
t.switchTrasparentNoteOff();
t.switchOnLights();
if(callback !== undefined) callback();
}).css({
'position': options.oldPosition.position,
});
}, 100);
};
if(scrollToNote && options.position != "fixed") {
t.scrollToNotePosition(options.oldPosition.top, options.height, options.oldPosition.left, options.width, showNote);
} else {
showNote();
}
},
//hide/show divList objects
toogleToolbar : function(action, divlist) {
var t = this;
var options = t.options;
var index = options.id;
var type = "";
var fadeOuTime = 200;
for(var i = 0; i < divlist.length; i++) {
type = divlist[i].substring(0,1);
if(type != "#" && type != ".") {
type = "#";
} else {
divlist[i] = divlist[i].substring(1);
}
//JESM
$(type + divlist[i] + index).fadeTo(0, 1, function() {
$(this).show();
});
/*
if(action == "hide") {
$(type + divlist[i] + index).fadeTo(0, 0, function() {
$(this).hide();
});
} else {
$(type + divlist[i] + index).fadeTo(0, 1, function() {
$(this).show();
});
}
*/
}
if ($.ui) $($.fn.postitall.globals.prefix + index).resizable("disable");
if ($.ui) $($.fn.postitall.globals.prefix + index).draggable("disable");
$(' .PIAeditable .PIAcontent .trumbowyg-editor').css('cursor', 'text');
t.hoverState = true;
/*
if(action == "hide") {
if ($.fn.postitall.globals.resizable && options.features.resizable) {
if ($.ui) $($.fn.postitall.globals.prefix + index).resizable("disable");
}
if ($.fn.postitall.globals.draggable && options.features.draggable) {
//draggable
if ($.ui) $($.fn.postitall.globals.prefix + index).draggable("disable");
$('#pia_toolbar_'+index).css('cursor', 'inherit');
}
} else {
if ($.fn.postitall.globals.resizable && options.features.resizable) {
if ($.ui) $($.fn.postitall.globals.prefix + index).resizable("enable");
}
if ($.fn.postitall.globals.draggable && options.features.draggable) {
if ($.ui) $($.fn.postitall.globals.prefix + index).draggable("enable");
$('#pia_toolbar_'+index).css('cursor', 'move');
}
t.hoverState = true;
//t.hoverOptions(index, true);
}
*/
},
//Expand note
expandNote : function() {
var t = this;
var index = t.options.id;
var options = t.options;
$('#the_lights_close').hide();
$('#pia_expand_' + index).removeClass('PIAexpand').addClass('PIAmaximize');
t.hoverOptions(index, false);
t.saveOldPosition();
//JESM
//t.toogleToolbar('hide', ['idPIAIconBottom_', 'idInfo_', 'pia_config_', 'pia_fixed_', 'pia_delete_', 'pia_blocked_', 'pia_minimize_', 'pia_new_', 'pia_hidden_']);
t.toogleToolbar('show', ['idPIAIconBottom_', 'idInfo_', 'pia_config_', 'pia_fixed_', 'pia_delete_', 'pia_blocked_', 'pia_minimize_', 'pia_new_', 'pia_hidden_']);
t.hideArrow();
t.switchTrasparentNoteOn();
t.switchOffLights();
// Expand note
$($.fn.postitall.globals.prefix + index).css({
'top':'10px',
'position': 'fixed',
}).animate({
'height': $(window).height() - 30,
'width': $(window).width() - 30,
'top': '10px',
'left': '10px',
}, 500, function() {
$('.PIApostit').css('z-index', 999995);
$(this).css('z-index', '999999');
$( "#pia_editable_" + index ).css('height',($(window).height() - 120));
$( "#pia_editable_" + index ).focus();
});
options.flags.expand = true;
t.enableKeyboardNav();
t.saveOptions(options);
},
//Collapse note (restoreOldPosition)
collapseNote : function() {
var t = this;
var index = t.options.id;
var options = t.options;
$('#the_lights_close').show();
$('#pia_expand_' + index).removeClass('PIAmaximize').addClass('PIAexpand');
$($.fn.postitall.globals.prefix + index).css('position', options.position);
// show toolbar
t.toogleToolbar('show', ['idPIAIconBottom_', 'idInfo_', 'pia_config_', 'pia_fixed_', 'pia_delete_', 'pia_blocked_', 'pia_minimize_', 'pia_new_', 'pia_hidden_']);
//restore oldposition
t.restoreOldPosition();
//newstate
options.flags.expand = false;
t.saveOptions(options);
},
//Minimize/Maximize note
minimizeNote : function() {
var t = this;
var index = t.options.id;
var options = t.options;
var obj = $($.fn.postitall.globals.prefix + index);
if(!$.fn.postitall.globals.minimized || !options.features.minimized)
return;
//minimize action
var minimize = function() {
t.hoverOptions(index, false);
$('#pia_editable_'+index).hide();
$('#pia_minimize_'+index).removeClass('PIAminimize').addClass('PIAmaximize');
options.flags.minimized = true;
//Add some start text to minimized note
var txtContent = " " + $('#pia_editable_'+index).text();
if(txtContent.length > 18)
txtContent = txtContent.substring(0,15) + "...";
var smallText = $('
').text(txtContent);
$('#pia_toolbar_'+index).append(smallText);
//hide toolbar
//JESM
//t.toogleToolbar('hide', ['idPIAIconBottom_', 'idInfo_', 'pia_config_', 'pia_fixed_', 'pia_delete_', 'pia_blocked_', 'pia_expand_', 'pia_new_', 'pia_hidden_']);
t.toogleToolbar('show', ['idPIAIconBottom_', 'idInfo_', 'pia_config_', 'pia_fixed_', 'pia_delete_', 'pia_blocked_', 'pia_expand_', 'pia_new_', 'pia_hidden_']);
//Enable draggable x axis
if ($.fn.postitall.globals.draggable && options.features.draggable) {
//draggable
if ($.ui) {
obj.draggable("enable");
obj.draggable({ axis: "x" });
}
}
t.saveOldPosition();
//Minimize
var hideNote = function() {
$($.fn.postitall.globals.prefix + index).animate({
'width': (options.minWidth + 20),
'height': '20px',
'bottom': '0',
'left': options.oldPosition.leftMinimized,
}, 500, function() {
t.hideArrow();
t.switchTrasparentNoteOn();
$($.fn.postitall.globals.prefix + index).css({position:'fixed'})
}).css({
'top': 'auto',
});
};
$($.fn.postitall.globals.prefix + index).css({
'position': 'fixed',
});
if(options.position == "absolute") {
$($.fn.postitall.globals.prefix + index).css({
'top': parseInt(options.posY, 10) - $(document).scrollTop(),
});
}
setTimeout(function(){
hideNote();
}, 100);
};
//maximize action (restoreOldPosition)
var maximize = function() {
t.restoreOldPosition(true, function() {
$('#pia_editable_'+index).show();
$('#pia_minimize_'+index).removeClass('PIAmaximize').addClass('PIAminimize');
options.flags.minimized = false;
// show toolbar
t.toogleToolbar('show', ['idPIAIconBottom_', 'idInfo_', 'pia_config_', 'pia_fixed_', 'pia_delete_', 'pia_blocked_', 'pia_expand_', 'pia_new_', 'pia_hidden_']);
$('#pia_minimized_text_'+index).remove();
//Remove draggable axis
if ($.fn.postitall.globals.draggable && options.features.draggable) {
if ($.ui) obj.draggable({ axis: "none" });
}
t.switchTrasparentNoteOff();
});
};
//Action
if(!options.flags.minimized) {
minimize();
} else {
maximize();
}
//Save feature
t.save(obj);
},
//Block note
blockNote : function() {
var t = this;
var index = t.options.id;
var options = t.options;
var obj = $($.fn.postitall.globals.prefix + index);
if(!$.fn.postitall.globals.blocked || !options.features.blocked)
return;
var ides = ['pia_config_', 'pia_fixed_', 'pia_delete_', 'idPIAIconBottom_', '.selectedArrow_'];
if(!options.flags.expand)
ides.push('pia_expand_');
if(!options.flags.minimized)
ides.push('pia_minimize_');
if(options.flags.blocked) {
$('#pia_blocked_'+index.toString()).removeClass('PIAblocked2').addClass('PIAblocked');
$('#pia_editable_'+index.toString()).attr('contenteditable', true).css("cursor", "");
//toolbar
t.toogleToolbar('show', ides);
//onhover actions
t.hoverOptions(index, true);
//new state
options.flags.blocked = false;
} else {
$('#pia_blocked_'+index.toString()).removeClass('PIAblocked').addClass('PIAblocked2');
$('#pia_editable_'+index.toString()).attr('contenteditable', false).css("cursor", "auto");
//disabel onhover actios
t.hoverOptions(index, false);
//toolbar
//JESM
//t.toogleToolbar('hide', ides);
t.toogleToolbar('show', ides);
//new state
options.flags.blocked = true;
}
//Save feature
t.save(obj);
},
//Fix note position
fixNote : function() {
var t = this;
var index = t.options.id;
var options = t.options;
var obj = $($.fn.postitall.globals.prefix + index);
if(options.flags.fixed) {
$('#pia_fixed_'+index).removeClass('PIAfixed2 PIAiconFixed').addClass('PIAfixed PIAicon');
options.position = "absolute";
options.posY = obj.offset().top;
obj.removeClass("fixed");
options.attachedTo.element = "";
options.flags.fixed = false;
} else {
$('#pia_fixed_'+index).removeClass('PIAfixed PIAicon').addClass('PIAfixed2 PIAiconFixed');
options.position = "fixed";
options.posY = parseInt(options.posY, 10) - $(document).scrollTop();
obj.addClass("fixed");
obj.css('z-index', 999996);
options.flags.fixed = true;
}
obj.css('position', options.position);
//obj.css('left', parseInt(options.posX, 10) + "px");
obj.css('top', parseInt(options.posY, 10) + "px");
//Save features
t.setOptions(options);
t.save(obj);
},
//Enable/Disable auto-hide toolbar icons when hover over the note
hoverOptions : function(index, enabled) {
//Hide toolbar
if(!$.fn.postitall.globals.toolbar || !this.options.features.toolbar)
return;
if(!$.fn.postitall.globals.autoHideToolBar || !this.options.features.autoHideToolBar)
enabled = false;
var fadeInTime = 200;
var fadeOuTime = 600;
var t = this;
if(enabled) {
setTimeout(function(){
//Options
$( $.fn.postitall.globals.prefix + index ).hover(function() {
$($.fn.postitall.globals.prefix + index).find('.PIAfront').find(".PIAicon, .PIAiconFixed").fadeTo(fadeInTime, 1);
if(t.options.style.arrow === undefined || t.options.style.arrow == "none")
$( $.fn.postitall.globals.prefix + index).find(".icon_box").fadeTo(fadeOuTime, 1);
$($.fn.postitall.globals.prefix + index + ' > .ui-resizable-handle').fadeTo(fadeInTime, 1);
t.hoverState = true;
}, function() {
setTimeout(function() {
if(!t.hoverState) {
$($.fn.postitall.globals.prefix + index).find('.PIAfront').find(".PIAicon, .PIAiconFixed").fadeTo(fadeOuTime, 0);
$($.fn.postitall.globals.prefix + index).find(".icon_box").fadeTo(fadeOuTime, 0);
$($.fn.postitall.globals.prefix + index + ' > .ui-resizable-handle').fadeTo(fadeOuTime, 0);
}
},(fadeOuTime - fadeInTime));
t.hoverState = false;
});
if(!t.hoverState) {
$($.fn.postitall.globals.prefix + index).find('.PIAfront').find(".PIAicon, .PIAiconFixed").fadeTo(fadeOuTime, 0);
$($.fn.postitall.globals.prefix + index).find(".icon_box").fadeTo(fadeOuTime, 0);
$($.fn.postitall.globals.prefix + index + ' > .ui-resizable-handle').fadeTo(fadeOuTime, 0);
}
},100);
return;
}
t.hoverState = false;
//Options
$( $.fn.postitall.globals.prefix + index ).unbind('mouseenter mouseleave');
//console.log('t.options.style.arrow',t.options.style.arrow);
if(t.options.style.arrow === undefined || t.options.style.arrow == "none")
$( $.fn.postitall.globals.prefix + index).find(".icon_box").fadeTo(fadeOuTime, 1);
$( $.fn.postitall.globals.prefix + index).find('.PIAfront').find(".PIAicon, .PIAiconFixed").fadeTo(fadeInTime, 1);
},
//Get a random color (if the feature is enabled, otherwhise will return default background color)
getRandomColor : function() {
var randomColor = "";
if($.fn.postitall.globals.randomColor && $.fn.postitall.defaults.features.randomColor) {
//Random color
//var colors = ["red", "blue", "yellow", "black", "green"];
//return colors[Math.floor(Math.random() * colors.length)];
randomColor = "#"+(Math.random()*0xFFFFFF<<0).toString(16);
} else {
//Default postit color
randomColor = $.fn.postitall.defaults.style.backgroundcolor;
}
if(randomColor.length < 7) {
var num = 7 - randomColor.length;
var ret = new Array( num + 1 ).join("0");
randomColor = randomColor + ret.toString();
}
return randomColor;
},
//Get text color relative tot hexcolor (if the featured is enabled, otherwise will return default text color)
getTextColor : function(hexcolor) {
if($.fn.postitall.globals.randomColor && $.fn.postitall.defaults.features.randomColor) {
//Inverse of background (hexcolor)
var nThreshold = 105;
var components = this.getRGBComponents(hexcolor);
var bgDelta = (components.R * 0.299) + (components.G * 0.587) + (components.B * 0.114);
return ((255 - bgDelta) < nThreshold) ? "#111111" : "#eeeeee";
} else {
//Default postit text color
return $.fn.postitall.defaults.style.textcolor;
}
},
//Get css text-shadow style
getTextShadowStyle : function(hexcolor) {
//console.log(hexcolor);
var nThreshold = 105;
var components = this.getRGBComponents(hexcolor);
var bgDelta = (components.R * 0.299) + (components.G * 0.587) + (components.B * 0.114);
return ((255 - bgDelta) < nThreshold) ? "tresdblack" : "tresd";
},
//Get rgb from an hex color
getRGBComponents : function(color) {
var r = color.substring(1, 3);
var g = color.substring(3, 5);
var b = color.substring(5, 7);
return {
R: parseInt(r, 16),
G: parseInt(g, 16),
B: parseInt(b, 16)
};
},
//Retrive unique random id (non savable notes)
guid : function() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
},
//Check if the element or her parents have a fixed position
elementOrParentIsFixed : function(element) {
var $element = $(element);
var $checkElements = $element.add($element.parents());
var isFixed = false;
$checkElements.each(function(){
if ($(this).css("position") === "fixed") {
isFixed = true;
return false;
}
});
return isFixed;
},
//Create note from an object
create : function(obj) {
var t = this;
var options = t.options;
var index = options.id.toString();
//Add data to object
obj.data('PIA-id', index)
.data('PIA-initialized', true)
.data('PIA-options', options);
//Postit editable content
if (options.content === "") {
if (obj.html() !== "") {
options.content = obj.html();
}
}
//Front page: toolbar
var barCursor = "cursor: inherit;";
if ($.fn.postitall.globals.draggable && options.features.draggable) {
barCursor = "cursor: move;";
}
var toolbar = $('
', {
'id': 'pia_toolbar_' + index,
'class': 'PIAtoolbar',
'style': barCursor
});
//Drag support without jQuery UI - don't work so much well...
if (!$.ui) {
if ($.fn.postitall.globals.draggable && options.features.draggable) {
toolbar.drags();
}
}
//Delete icon
if($.fn.postitall.globals.removable) {
if (options.features.removable) {
toolbar.append($('
', {
'id': 'pia_delete_' + index,
'class': 'PIAdelete PIAicon',
'title': 'Cerrar nota actual', //JESM
}).click(function (e) {
if (obj.hasClass('PIAdragged')) {
obj.removeClass('PIAdragged');
} else {
if($.fn.postitall.globals.askOnDelete && options.features.askOnDelete) {
if ($(this).parent().find('.ui-widget2').length <= 0) {
$('.backContent_' + index).hide();
$('#idBackDelete_' + index + ' > .PIABox').css({
//'width': options.width - 10,
'height': options.height - 40
});
$('#idBackDelete_' + index).show();
t.switchBackNoteOn('PIAflip2');
t.switchOffLights();
}
} else {
t.destroy();
}
}
e.preventDefault();
}));
}
}
//Config icon
if($.fn.postitall.globals.changeoptions) {
if (options.features.changeoptions) {
toolbar.append(
$('
', {
'id': 'pia_config_' + index,
'class': 'PIAconfig PIAicon',
'title': 'Configuración de colores', //JESM
}).click(function (e) {
if (obj.hasClass('PIAdragged')) {
obj.removeClass('PIAdragged');
} else {
$('.backContent_'+index).hide();
$('#idBackConfig_'+index+' > .PIABox').css({
//'width': options.width - 10,
'height': options.height - 40
});
$('#idBackConfig_'+index).show();
t.switchBackNoteOn('PIAflip2');
}
e.preventDefault();
})
);
}
}
//Fixed
if($.fn.postitall.globals.fixed) {
if(options.features.fixed) {
toolbar.append(
$('
', {
'id': 'pia_fixed_' + index,
'class': 'PIAfixed' + (options.flags.fixed ? '2 PIAiconFixed' : ' PIAicon') + ' '
}).click(function (e) {
if (obj.hasClass('PIAdragged')) {
obj.removeClass('PIAdragged');
} else {
t.fixNote();
}
e.preventDefault();
})
);
}
}
//Hide
if($.fn.postitall.globals.hidden && options.features.hidden) {
toolbar.append(
$('
', {
'id': 'pia_hidden_' + index,
'class': 'PIAhide PIAicon',
'title': 'Esconde la nota', //JESM
}).click(function(e) {
if(obj.hasClass('PIAdragged')) {
obj.removeClass('PIAdragged');
} else {
if($.fn.postitall.globals.askOnHide && options.features.askOnHide) {
$('.backContent_'+index).hide();
$('#idHideUntil_'+index+' > .PIABox').css({
//'width': options.width - 10,
'height': options.height - 40
});
$('#idHideUntil_'+index).show();
t.switchBackNoteOn('PIAflip2');
} else {
t.hide(index);
}
}
e.preventDefault();
})
);
} else {
options.flags.hidden = false;
}
//MINIMIZE
if($.fn.postitall.globals.minimized && options.features.minimized) {
toolbar.append(
$('
', {
'id': 'pia_minimize_' + index,
'class': (options.flags.minimized ? 'PIAmaximize' : 'PIAminimize') + ' PIAicon',
'title': 'Minimiza la nota', //JESM
}).click(function (e) {
if (obj.hasClass('PIAdragged')) {
obj.removeClass('PIAdragged');
} else {
t.minimizeNote();
}
e.preventDefault();
})
);
} else {
options.flags.minimized = false;
}
//Expand note / Maximize
if($.fn.postitall.globals.expand && options.features.expand) {
toolbar.append(
$('
', {
'id': 'pia_expand_' + index,
'class': (options.flags.expand ? 'PIAmaximize' : 'PIAexpand') + ' PIAicon',
'title': 'Expande la nota', //JESM
}).click(function (e) {
if (obj.hasClass('PIAdragged')) {
obj.removeClass('PIAdragged');
} else {
if(!options.flags.expand) {
t.expandNote();
} else {
t.collapseNote();
}
}
e.preventDefault();
})
);
} else {
options.flags.expand = false;
}
//Botón guardar JESM
toolbar.append(
$('
', {
'id': 'pia_saveNote_' + index,
'class': 'guardar_notas',
'title' : 'Guardar el contenido de la nota',
'html' : 'Guardar'
}).click(function (e) {
var idNota = prefixNotes + this.id.substring(("pia_saveNote_").length);
guardar_nota(idNota, true);
//Revisa si es una nota nueva para eliminarla de las notas no guardados y que son nuevas
//Ya que dentro de guardar_nota se agregó al arreglo currentNotes
var idx = unSavedNotes.indexOf(idNota)
if (idx >= 0){
unSavedNotes.splice(idx,1);
}
e.preventDefault();
})
);
//Blocked
if($.fn.postitall.globals.blocked && options.features.blocked) {
toolbar.append(
$('
', {
'id': 'pia_blocked_' + index,
'class': 'PIAblocked' + (options.flags.blocked == true ? '2' : '') + ' PIAicon',
'title' : 'Bloquea la nota', //JESM
}).click(function (e) {
if (obj.hasClass('PIAdragged')) {
obj.removeClass('PIAdragged');
} else {
t.blockNote();
}
e.preventDefault();
})
);
}
//Front page: content
var content = $('
', {
'id': 'pia_editable_' + index,
'class': 'PIAeditable PIAcontent',
'placeholder': 'Escribe tu nota aquí', //JESM
//Reset herisated contenteditable styles
//color:'+options.style.textcolor+';min-width:99%;
//JESM-ENE2021
//'style': 'width: auto;height: auto;padding: 10px;border-color: transparent;min-width:' + (options.minWidth) + 'px;box-shadow:none;min-height:' + (options.minHeight - 100) + 'px;'
'style': 'width: auto;height: auto;padding: 10px;border-color: transparent;box-shadow:none; overflow: auto;'
}).change(function (e) {
if(!$.fn.postitall.globals.editable || !options.features.editable) {
return;
}
var oldContent = options.content;
//Html format
var text = $(this).text();
if ($.fn.postitall.globals.pasteHtml || options.features.pasteHtml) {
text = $(this).html();
//Default sanitize
text = text.replace(/