summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/util.js154
-rw-r--r--js/xbImportNode.js46
2 files changed, 119 insertions, 81 deletions
diff --git a/js/util.js b/js/util.js
index 111beef25..151c0d111 100644
--- a/js/util.js
+++ b/js/util.js
@@ -17,94 +17,86 @@
*/
$(document).ready(function(){
- // count character on keyup
- function counter(event){
- var maxLength = 140;
- var currentLength = $("#status_textarea").val().length;
- var remaining = maxLength - currentLength;
- var counter = $("#counter");
- counter.text(remaining);
+ // count character on keyup
+ function counter(event){
+ var maxLength = 140;
+ var currentLength = $("#status_textarea").val().length;
+ var remaining = maxLength - currentLength;
+ var counter = $("#counter");
+ counter.text(remaining);
+
+ if (remaining <= 0) {
+ counter.addClass("toomuch");
+ } else {
+ counter.removeClass("toomuch");
+ }
+ }
- if (remaining <= 0) {
- counter.attr("class", "toomuch");
- } else {
- counter.attr("class", "");
- }
- }
+ function submitonreturn(event) {
+ if (event.keyCode == 13) {
+ $("#status_form").submit();
+ event.preventDefault();
+ event.stopPropagation();
+ return false;
+ }
+ return true;
+ }
- function submitonreturn(event) {
- if (event.keyCode == 13) {
- $("#status_form").submit();
- event.preventDefault();
- event.stopPropagation();
- return false;
- }
- return true;
- }
+ if ($("#status_textarea").length) {
+ $("#status_textarea").bind("keyup", counter);
+ $("#status_textarea").bind("keydown", submitonreturn);
+
+ // run once in case there's something in there
+ counter();
+
+ // set the focus
+ $("#status_textarea").focus();
+ }
- if ($("#status_textarea").length) {
- $("#status_textarea").bind("keyup", counter);
- $("#status_textarea").bind("keydown", submitonreturn);
+ // XXX: refactor this code
- // run once in case there's something in there
- counter();
+ var favoptions = { dataType: 'xml',
+ success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
+ var dis = new_form.id;
+ var fav = dis.replace('disfavor', 'favor');
+ $('form#'+fav).replaceWith(new_form);
+ $('form#'+dis).ajaxForm(disoptions).each(addAjaxHidden);
+ }
+ };
- // set the focus
- $("#status_textarea").focus();
- }
+ var disoptions = { dataType: 'xml',
+ success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
+ var fav = new_form.id;
+ var dis = fav.replace('favor', 'disfavor');
+ $('form#'+dis).replaceWith(new_form);
+ $('form#'+fav).ajaxForm(favoptions).each(addAjaxHidden);
+ }
+ };
- // XXX: refactor this code
+ function addAjaxHidden() {
+ var ajax = document.createElement('input');
+ ajax.setAttribute('type', 'hidden');
+ ajax.setAttribute('name', 'ajax');
+ ajax.setAttribute('value', 1);
+ this.appendChild(ajax);
+ }
- var favoptions = {dataType: 'xml',
- success: function(xml) {
- var new_form = $('form.disfavor', xml).get(0);
- var dis = new_form.id;
- var fav = dis.replace('disfavor', 'favor');
- if (document.importNode) {
- new_form = document.importNode(new_form, true);
- }
- $('form#'+fav).replaceWith(new_form);
- $('form#'+dis).ajaxForm(disoptions).each(addAjaxHidden);
- }};
-
- var disoptions = {dataType: 'xml',
- success: function(xml) {
- var new_form = $('form.favor', xml).get(0);
- var fav = new_form.id;
- var dis = fav.replace('favor', 'disfavor');
- if (document.importNode) {
- new_form = document.importNode(new_form, true);
- }
- $('form#'+dis).replaceWith(new_form);
- $('form#'+fav).ajaxForm(favoptions).each(addAjaxHidden); ;
- }};
-
- function addAjaxHidden() {
- var ajax = document.createElement('input');
- ajax.setAttribute('type', 'hidden');
- ajax.setAttribute('name', 'ajax');
- ajax.setAttribute('value', 1);
- this.appendChild(ajax);
- }
-
- $("form.favor").ajaxForm(favoptions);
- $("form.disfavor").ajaxForm(disoptions);
-
- $("form.favor").each(addAjaxHidden);
- $("form.disfavor").each(addAjaxHidden);
+ $("form.favor").ajaxForm(favoptions);
+ $("form.disfavor").ajaxForm(disoptions);
+ $("form.favor").each(addAjaxHidden);
+ $("form.disfavor").each(addAjaxHidden);
});
function doreply(nick,id) {
- rgx_username = /^[0-9a-zA-Z\-_.]*$/;
- if (nick.match(rgx_username)) {
- replyto = "@" + nick + " ";
- if ($("#status_textarea").length) {
- $("#status_textarea").val(replyto);
- $("form#status_form input#inreplyto").val(id);
- $("#status_textarea").focus();
- return false;
- }
- }
- return true;
-}
-
+ rgx_username = /^[0-9a-zA-Z\-_.]*$/;
+ if (nick.match(rgx_username)) {
+ replyto = "@" + nick + " ";
+ if ($("#status_textarea").length) {
+ $("#status_textarea").val(replyto);
+ $("form#status_form input#inreplyto").val(id);
+ $("#status_textarea").focus();
+ return false;
+ }
+ }
+ return true;
+} \ No newline at end of file
diff --git a/js/xbImportNode.js b/js/xbImportNode.js
new file mode 100644
index 000000000..4ba332a68
--- /dev/null
+++ b/js/xbImportNode.js
@@ -0,0 +1,46 @@
+/* is this stuff defined? */
+if (!document.ELEMENT_NODE) {
+ document.ELEMENT_NODE = 1;
+ document.ATTRIBUTE_NODE = 2;
+ document.TEXT_NODE = 3;
+ document.CDATA_SECTION_NODE = 4;
+ document.ENTITY_REFERENCE_NODE = 5;
+ document.ENTITY_NODE = 6;
+ document.PROCESSING_INSTRUCTION_NODE = 7;
+ document.COMMENT_NODE = 8;
+ document.DOCUMENT_NODE = 9;
+ document.DOCUMENT_TYPE_NODE = 10;
+ document.DOCUMENT_FRAGMENT_NODE = 11;
+ document.NOTATION_NODE = 12;
+}
+
+document._importNode = function(node, allChildren) {
+ /* find the node type to import */
+ switch (node.nodeType) {
+ case document.ELEMENT_NODE:
+ /* create a new element */
+ var newNode = document.createElement(node.nodeName);
+ /* does the node have any attributes to add? */
+ if (node.attributes && node.attributes.length > 0)
+ /* add all of the attributes */
+ for (var i = 0, il = node.attributes.length; i < il;) {
+ if (node.attributes[i].nodeName == 'class') {
+ newNode.className = node.getAttribute(node.attributes[i++].nodeName);
+ } else {
+ newNode.setAttribute(node.attributes[i].nodeName, node.getAttribute(node.attributes[i++].nodeName));
+ }
+ }
+ /* are we going after children too, and does the node have any? */
+ if (allChildren && node.childNodes && node.childNodes.length > 0)
+ /* recursively get all of the child nodes */
+ for (var i = 0, il = node.childNodes.length; i < il;)
+ newNode.appendChild(document._importNode(node.childNodes[i++], allChildren));
+ return newNode;
+ break;
+ case document.TEXT_NODE:
+ case document.CDATA_SECTION_NODE:
+ case document.COMMENT_NODE:
+ return document.createTextNode(node.nodeValue);
+ break;
+ }
+}; \ No newline at end of file