BecameEmpty: function(sender, args);
sender. Event source.
args. Information on the event.
The BecameEmpty event occurs after a term becomes empty.
To execute the example, the HTML page must contain links to the PP.js and PP.Ufe.js scenario files and PP.css and PP.Ufe.css styles files in the <body> tag of HTML document of the <div> element with the "termedit" identifier. Create a term editor on the HTML page and add several terms:
function createTerm() { // Create a term editor termEdit = new PP.Ui.TermEdit({ // Set parent element ParentNode: document.getElementById("termEdit") }); // Add string value to editor termEdit.insertString("100"); // Add data to editor termEdit.insertData([new PP.Ui.Term({ Content: "+", Formula: "+" })]); // Add term to editor termEdit.insertString("20"); }
As a result several terms are added to the term editor:
Put the cursor to the term with the 20 contents. Get the obtained term and add the BecameEmpty event handler to it, as well, get start and end term positions in the expression and check if the term contains one character:
// Get the selected term term = termEdit.getSelectedTerm(); // Add the processing of the event of becoming empty to the selected term term.BecameEmpty.add(function (sender, args) { console.log("The selected term became empty"); }, term); // Get the number of start term position console.log("Start term position: " + term.getStartOffset()); // Get the number of end term position console.log("End term position: " + term.getEndOffset()); // Check if the selected term contains one character if (term.getIsOneCharTerm()) { console.log("The selected term contains one character"); } else { console.log("The selected term does not contain one character"); }
As a result the console displays the start and end position of the selected term:
Start term position: 4
End term position: 6
The selected term does not contain one character
Check if formula of the selected term can be edited:
// Check if formula of the selected term can be edited if (term.canEditFormula()) { console.log("Term formula can be edited"); } else { console.log("Term formula cannot be edited"); }
As a result the console displays check result:
Term formula can be edited
Delete the first and the last term characters:
// Delete the last term character term.deleteLastChar(); // Delete the first term character term.deleteFirstChar(); // Refresh editor terms termEdit.updateTerms();
As a result the term with the 20 contents is missing in the term editor:
The console displays a message that the selected term became empty:
The selected term became empty
See also: