[Tutorial] Botão para salvar textos |
- Código:
/* Botão Salvar Texto */
#savec { position:relative; }
.save-bloc { dispay: none; color: #555!important; cursor: point; z-index: 1000; padding: 5px; border: 1px solid #BCBCBC; background: #efefef url(http://2img.net/i/fa/prosilver/bg_button.gif) repeat-x; display:none;top:20px;left:0px;position:absolute; white-space:nowrap; }
.save-bloc div:hover { color: #050505!important; }
.save-bloc div { cursor: pointer; }
.save-bloc select { background: #ccc; border: 1px solid #aaa; margin-bottom: 5px;
}
/*---/ Creditos: 2012 Staffer Group BR /---*/
/*---/ http://staffergroupbr.stuning.net /---*/
Painel de Controle Módulos HTML & JavaScript Gestão de códigos JavaScript
Título * : Opcional.
Investimento :
Código JavaScript * : Cole o código abaixo.
- Código:
function insertText(a) {
var c = localStorage.getItem("fasave" + a);
if(null === c) {
$("#savep div[onClick^='insertText(" + a + ")']").remove()
}else {
if(1 == $("#savep select").val()) {
localStorage.removeItem("fasave" + a), localStorage.removeItem("fasavet" + a), $("#savep div[onClick^='insertText(" + a + ")']").remove()
}else {
if(2 == $("#savep select").val()) {
var b = localStorage.getItem("fasavet" + a), b = prompt("Entrer le titre de la sauvegarde :", b ? b : "");
null !== b && ("" == b ? (localStorage.removeItem("fasavet" + a), $("#savep div[onClick^='insertText(" + a + ")']").text('"' + c.substr(0, 30).replace(/</g, "<").replace(/>/g, ">") + (30 < c.length ? "..." : '"'))) : (localStorage.setItem("fasavet" + a, b), $("#savep div[onClick^='insertText(" + a + ")']").text(b)))
}else {
replaceTxt(c)
}
}
}
}
function replaceTxt(a) {
var c = $("#text_editor_textarea");
if(c.length) {
start = c[0].selectionStart;
end = c[0].selectionEnd;
stop = c[0].scrollTop;
sleft = c[0].scrollLeft;
text = c.val();
for(var b = [""], e = /^([\s\S]*?)(((\$\$)+)(\$?)|(\$))0([\s\S]*)$/, d;d = a.match(e);) {
b[b.length - 1] += d[1], "$" == d[6] || "" == d[4] ? b[b.length] = "" : b[b.length - 1] += d[3].substr(0, d[3].length / 2) + "0", a = d[7]
}
b[b.length - 1] = a;
e = text.substring(start, end);
a = b[0];
d = a.length;
for(var f = 1;f < b.length;f++) {
a += e, a += b[f]
}
c.val(text.substr(0, start) + a + text.substr(end));
c[0].selectionStart = start + d;
c[0].selectionEnd = 1 < b.length ? end + d : start + d;
c[0].scrollTop = stop;
c[0].scrollLeft = sleft
}
}
function saveExport() {
for(var a = null === localStorage.getItem("fasave-length") ? 0 : localStorage.getItem("fasave-length"), c = "[", b = 0;b < a;b++) {
var e = localStorage.getItem("fasave" + b);
if(null !== e) {
var d = localStorage.getItem("fasavet" + b);
"[" != c && (c += ",");
c += (null === d ? "" : escape(d) + ":") + escape(e)
}
}
replaceTxt(c + "]")
}
function saveImport() {
var a = $("#text_editor_textarea").val().substring($("#text_editor_textarea").prop("selectionStart"), $("#text_editor_textarea").prop("selectionEnd")).replace(/\s/g, "");
if(/^\[[%/^a-zA-Z0-9\*@_\+\.\/:,-]*\]$/.test(a)) {
for(var a = a.substr(1, a.length - 2).split(","), c = 0;c < a.length;c++) {
var b = a[c].split(":");
2 == b.length ? saveItem(unescape(b[1]), unescape(b[0])) : saveItem(unescape(b[0]), "")
}
}
}
function saveSelect() {
var a = $("#text_editor_textarea");
0 != $(a).prop("selectionStart") - $(a).prop("selectionEnd") && (a = a.val().substring($(a).prop("selectionStart"), $(a).prop("selectionEnd")), saveItem(a, ""))
}
function saveItem(a, c) {
for(var b = parseInt(null === localStorage.getItem("fasave-length") ? 0 : localStorage.getItem("fasave-length")), e = 0;e < b;e++) {
var d = localStorage.getItem("fasave" + e);
null !== d && d == a && (localStorage.removeItem("fasavet" + e), $("#savep div[onClick^='insertText(" + e + ")']").remove(), localStorage.removeItem("fasave" + e))
}
localStorage.setItem("fasave" + b, a);
"" != c && localStorage.setItem("fasavet" + b, c);
localStorage.setItem("fasave-length", b + 1);
$("#savep select").after('<div class="savedt" onClick="insertText(' + b + ');return false;">' + (c ? c : """ + a.substr(0, 30).replace(/</g, "<").replace(/>/g, ">") + (30 < a.length ? "..." : """)) + "</div>")
}
$(function() {
$("#text_editor_textarea").length && window.localStorage && "Microsoft Internet Explorer" != navigator.appName && ($("#addbbcode16").after(' <span id="savec"><button id="saveb" class="button2" type="button" title="Sauvegarde"><img src="http://i49.servimg.com/u/f49/15/59/73/38/save10.png" alt="Sauvegarde" title="Salvar Texto"></button></span>'), $("#saveb").click(function(a) {
if(a.shiftKey) {
$("#saveshift").length || $("#savec").append('<div class="save-bloc" id="saveshift"><div onClick="saveExport()">Exporter</div><div onClick="saveImport()">Importer</div></div>'), $("#savep").hide(300), $("#saveshift").slideToggle(300)
}else {
if(!$("#savep").length) {
$("#savec").append('<div class="save-bloc" id="savep"><select><option value="0">Insérer</option><option value="1">Supprimer</option><option value="2">Nommer</option></select><div id="saves" style="display:none"><hr /><span onClick="saveSelect()">Sauver la sélection</span></div></div>');
$("#savep").click(function(a) {
a.stopPropagation()
});
for(var a = null === localStorage.getItem("fasave-length") ? 0 : localStorage.getItem("fasave-length"), c = 0;c < a;c++) {
var b = localStorage.getItem("fasave" + c);
null !== b && $("#savep select").after('<div class="savedt" onClick="insertText(' + c + ');return false;">' + (null === localStorage.getItem("fasavet" + c) ? """ + b.substr(0, 30).replace(/</g, "<").replace(/>/g, ">") + (30 < b.length ? "..." : """) : localStorage.getItem("fasavet" + c)) + "</div>")
}
}
$("#saveshift").hide(300);
$("#savep").slideToggle(300)
}
}), $("#text_editor_textarea").select(function() {
$("#saves").show()
}), $("#text_editor_textarea").bind("click keyup keydown", function() {
0 == $(this).prop("selectionStart") - $(this).prop("selectionEnd") && $("#saves").hide()
}))
});
Clique na imagem para visualizar ▲
Desenvolvido por Etna | Forum des Forums
Editado e Postado por Copyright® 2012 Staffer Group BR
Editado e Postado por Copyright® 2012 Staffer Group BR