Finish work on webui project notes

This commit is contained in:
Alvaro Muñoz 2015-02-10 13:50:41 +01:00 committed by pancake
parent 0a7b7ed91e
commit eb94217df0
7 changed files with 56 additions and 33 deletions

File diff suppressed because one or more lines are too long

View File

@ -1025,9 +1025,4 @@ function inColor(x) {
return "e scr.color=true;"+x+";e scr.color=false";
}
function save_project_notes() {
if ($("#pnotes").val() === r2ui.project_notes) {
console.log("Saving " + r2ui.project_notes);
r2.cmd("Pnj " + btoa(r2ui.project_notes));
}
}

View File

@ -97,7 +97,9 @@ enyo.kind ({
var key = String.fromCharCode(keynum);
// console.log(key);
if (inEvent.ctrlKey||inEvent.metaKey) return true;
if (inEvent.ctrlKey||inEvent.metaKey) return;
if ($(inEvent.target).prop("tagName") === "INPUT" || $(inEvent.target).prop("tagName") === "TEXTAREA") return;
// show help
if (key === '?') {

View File

@ -101,7 +101,6 @@ r2ui.update_fcn_BB = function(fcn_offset, bb_offset, bbinfo) {
}
};
r2ui.project_notes = "";
r2ui.current_fcn_offset = null;
r2ui.graph = null;
r2ui.console_lang = "r2";

View File

@ -30,6 +30,7 @@
<script type="text/javascript" src="./lib/js/taphold.js"></script>
<script type="text/javascript" src="./lib/js/jquery.ui-contextmenu.js"></script>
<script type="text/javascript" src="./lib/js/jquery.layout-latest.js"></script>
<script type="text/javascript" src="./lib/js/jquery.donetyping.js"></script>
<script type="text/javascript" src="./lib/js/tree.jquery.js"></script>
<script type="text/javascript" src="./lib/js/jquery.layout.resizePaneAccordions-latest.js"></script>
<script type="text/javascript" src="./lib/js/jquery.scrollTo-latest.js"></script>

View File

@ -0,0 +1,36 @@
;(function($){
$.fn.extend({
donetyping: function(callback,timeout){
timeout = timeout || 1e3; // 1 second default timeout
var timeoutReference,
doneTyping = function(el){
if (!timeoutReference) return;
timeoutReference = null;
callback.call(el);
};
return this.each(function(i,el){
var $el = $(el);
// Chrome Fix (Use keyup over keypress to detect backspace)
// thank you @palerdot
$el.is(':input') && $el.on('keyup keypress',function(e){
// This catches the backspace button in chrome, but also prevents
// the event from triggering too premptively. Without this line,
// using tab/shift+tab will make the focused element fire the callback.
if (e.type=='keyup' && e.keyCode!=8) return;
// Check if timeout has been set. If it has, "reset" the clock and
// start over again.
if (timeoutReference) clearTimeout(timeoutReference);
timeoutReference = setTimeout(function(){
// if we made it here, our timeout has elapsed. Fire the
// callback
doneTyping(el);
}, timeout);
}).on('blur',function(){
// If we can, fire the event since we're leaving the field
doneTyping(el);
});
});
}
});
})(jQuery);

View File

@ -278,23 +278,16 @@ $(document).ready( function() {
// Project notes
r2.cmdj("Pnj", function(x){
// TODO: Handle when project does not exist
// TODO: remove keyhandlers from pnotes
if (x !== null) {
console.log(x);
var notes = atob(x);
$("#pnotes").html(notes);
}
if (x !== null) $("#pnotes").html(atob(x));
});
$("#pnotes").bind("keydown", function(x) {
r2ui.project_notes = $("#pnotes").val();
setTimeout("save_project_notes();", 3000);
$("#pnotes").donetyping(function() {
r2.cmd("Pnj " + btoa($("#pnotes").val()));
r2.cmd("Po", function(x) {
if (x === "") alert("Notes won't be persited until a project is opened. Use Project's tab or 'Ps name' to save current project");
});
});
});
function scroll_to_element(element) {
if (element === undefined) return;
var top = Math.max(0,element.documentOffsetTop() - ( window.innerHeight / 2 ));
@ -324,11 +317,8 @@ function handleKeypress(inEvent) {
var key = String.fromCharCode(keynum);
// console.log(key);
if (inEvent.ctrlKey||inEvent.metaKey) return true;
if ($(inEvent.target).prop("tagName") === "INPUT") {
return;
};
if (inEvent.ctrlKey||inEvent.metaKey) return;
if ($(inEvent.target).prop("tagName") === "INPUT" || $(inEvent.target).prop("tagName") === "TEXTAREA") return;
if (r2ui._dis.renaming !== null) return;