Código de JavaScript - Nota Autoadhesiva en javascript

sin imagen de perfil
Val: 91
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Nota Autoadhesiva en javascriptgráfica de visualizaciones


JavaScript

Publicado el 17 de Noviembre del 2015 por Alfredo (2 códigos)
3.180 visualizaciones desde el 17 de Noviembre del 2015
Código que permite agregar notas autoadhesivas a tu página de intranet.
Sólo debes tener las librerías requeridas y que tu explorador soporte IndexedDB.

A la izquierda de tu explorador aparece una pequeña pestaña con dos opciones. Un signo de más que agrega automáticamente una nota en tu pantalla y un ojo para ocultar y/o mostrar todas las notas.

Cuando termines de usar la nota solo haz click en la X de la nota y podrás borrar la nota.


2015-08-24-08_52_56-Inicio-STEAM
2015-08-24-08_53_09-Inicio-STEAM
2015-08-24-08_53_24-Inicio-STEAM

Requerimientos

Bootstrap
JQuery
JQueryUI
El Explorador debe soportar IndexedDB

Versión 1.0.0
estrellaestrellaestrellaestrellaestrella(4)

Publicado el 17 de Noviembre del 2015gráfica de visualizaciones de la versión: Versión 1.0.0
739 visualizaciones desde el 17 de Noviembre del 2015

Versión 1.0.1
estrellaestrellaestrellaestrellaestrella(4)

Publicado el 19 de Noviembre del 2015gráfica de visualizaciones de la versión: Versión 1.0.1
2.442 visualizaciones desde el 19 de Noviembre del 2015
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

Esta versión incluye implementación del código y se agregó el cursor de movimiento para indicar que la nota se puede mover.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html>
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-MfvZlkHCEqatNoGiOXveE8FIwMzZg4W85qfrfIFBfYc= sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<style>
.contenedorDeNotas
{
    position:absolute;
    z-index:1;
    border:1px solid black;
    width:50px;
    height:40px;
    top:100px;
    transition: 0.75s;
    left:-30px;
    background-color:#FFFFFF;
    margin-left:-10px;
    padding-left:0px;
    border-bottom-right-radius:10px;
    border-top-right-radius:10px;
}
.contenedorDeNotas:hover {
    transition: 0.5s;
    left: 5px;
}
 
 
 
.notas
{
    width: 250px; height: 150px; padding: 0.5em;
    background-color:#EDDA74;
    border:1px solid #ADA96E;
    position:absolute;
    border-top-left-radius:10px;
    box-shadow: 10px 10px 5px #888888;
 
}
.notas textarea
{
    font-size:12px;
    font-family:Arial;
    border-style:none;
    resize:none;
    background-color: inherit;
}
</style>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script>
 
var dbNotas;
$(function () {
    if ("indexedDB" in window)
    {
        var openRequest = indexedDB.open("notasDB", 1);
        openRequest.onupgradeneeded = function (e)
        {
            var thisDB = e.target.result;
            if (!thisDB.objectStoreNames.contains("notas")) {
                thisDB.createObjectStore("notas", { keyPath: "id", autoIncrement: true });
            }
            if (!thisDB.objectStoreNames.contains("preferencias")) {
                thisDB.createObjectStore("preferencias", { autoIncrement: true });
            }
        }
        openRequest.onsuccess = function (e)
        {
            dbNotas = e.target.result;
            crearContenedorDeNotas();
            generarNotas();
        }
        openRequest.onerror = function (e){console.log("Error");console.dir(e);}
    }
});
function crearContenedorDeNotas() {
    var cuadro = document.createElement("div");
    cuadro.id = "contenedorDeNotas";
    cuadro.className = "contenedorDeNotas";
    cuadro.innerHTML = "<div style='float:left;height:100%'><a href='javascript:agregarNota(100,100,1,\"\")' style='padding-left:10px;'><span class='glyphicon glyphicon-plus'/></a><br/><span style='padding-left:10px;padding-top:5px' id='statusNotas'><a href='javascript:ocultarNotas()'><span class='glyphicon glyphicon-eye-close'/></a></span></div><div style='width:5px;background-color:#F5F5F5;height:100%;float:right;padding-right:12px; border-bottom-right-radius:10px;border-top-right-radius:10px;cursor:pointer;'>&nbsp;</div>";
    document.body.appendChild(cuadro);
}
function ocultarNotas()
{
    $("div.notas").css("display", "none");
    document.getElementById("statusNotas").innerHTML = "<a href='javascript:mostrarNotas()'><span class='glyphicon glyphicon-eye-open'/></a>";
}
function mostrarNotas() {
    $("div.notas").css("display", "");
    document.getElementById("statusNotas").innerHTML = "<a href='javascript:ocultarNotas()'><span class='glyphicon glyphicon-eye-close'/></a>";
}
 
function actualizarNotas(elemento)
{
    var id = elemento.dataset.id;
    var request = dbNotas.transaction(["notas"]).objectStore("notas").get(Number(id));
    request.onsuccess = function(event)
    {
        creado = request.result.creado;
        var nota = dbNotas.transaction(["notas"], "readwrite");
        var offset = $(elemento).parent().offset();
        var x = offset.left;
        var y = offset.top;
        var z = $(elemento).parent().zIndex();
        nota.objectStore("notas").put({
                                  contenido: elemento.value,
                                  x: x,
                                  y: y,
                                  z: z,
                                  creado :creado,
                                  id: Number(id)
                              });
        nota.oncomplete = function (event) { };
    };
}
 
 
function agregarNota(x, y, z, nota) {
    if (String(document.getElementById("statusNotas").innerHTML).indexOf("mostrarNotas()") == -1)
    {
        var transaction = dbNotas.transaction(["notas"], "readwrite");
        var store = transaction.objectStore("notas");
        var notaobj = { x: x, y: y, z: z, contenido: nota, creado: new Date() };
        var request = store.add(notaobj);
        request.onerror = function (e) { console.log("Error", e.target.error.name); }
        request.onsuccess = function (event){generarNotas();}
    }
    else {alert("Favor mostrar las notas antes de agregar una nueva");}
}
 
function eliminarNota(id) {
    var eliminar = confirm("Esta seguro que desea eliminar esta nota?");
    if (eliminar)
    {
        var t = dbNotas.transaction(["notas"], "readwrite");
        var request = t.objectStore("notas").delete(id);
        t.oncomplete = function (event) {};
        generarNotas();
    }
}
function generarNotas()
{
    $("div.notas").remove();
    dbNotas.transaction(["notas"], "readonly").objectStore("notas").openCursor().onsuccess = function (e) {
        var cursor = e.target.result;
        if (cursor)
        {
            var x = cursor.value["x"];
            var y = cursor.value["y"];
            var z = cursor.value["z"];
            var cuadro = document.createElement("div");
            cuadro.id = "NOTA" + cursor.value["id"];
            cuadro.className = "notas";
            cuadro.innerHTML = "<div style='text-align:right;cursor:move'>" + (new Date(cursor.value["creado"])).toLocaleString() + "<a href='javascript:eliminarNota(" + cursor.value["id"] + ")' style='font-family:arial'><span class='glyphicon glyphicon-remove'/></a></div><textarea style='width:100%;height:90%;' data-id='" + cursor.value["id"] + "' onblur='javascript:actualizarNotas(this);' placeholder='...'>" + cursor.value["contenido"] + "</textarea>";
            cuadro.style.top = y + "px";
            cuadro.style.left = x + "px";
            document.body.appendChild(cuadro);
            $(function () {$("#NOTA" + cursor.value["id"]).draggable({stop: function () {actualizarNotas(this.getElementsByTagName("textarea")[0]);}});});
            cursor.continue();
        }
    };
}
</script>
</head>
 
<body>
</body>
 
</html>



Comentarios sobre la versión: Versión 1.0.1 (4)

Imágen de perfil
20 de Noviembre del 2015
estrellaestrellaestrellaestrellaestrella
Felicidades Alfredo es Impresionante!!!

Te agradezco que compartas la versión funcional!!!
Responder
24 de Noviembre del 2015
estrellaestrellaestrellaestrellaestrella
De nada. Saludos!
Responder
24 de Noviembre del 2015
estrellaestrellaestrellaestrellaestrella
muy buen código, excelente amigo sigue asi
Responder
24 de Noviembre del 2015
estrellaestrellaestrellaestrellaestrella
Gracias!
Responder

Comentar la versión: Versión 1.0.1

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s3347