src/js/widgets/createAnnotationWidget.js
branchpopcorn-port
changeset 611 d931a7d12519
parent 608 2fb4eda4dcd2
child 614 116de1c38a7d
equal deleted inserted replaced
610:7533dd920805 611:d931a7d12519
    37     
    37     
    38     this.selector.find(".Ldt-createAnnotation-keywords").append(templ);
    38     this.selector.find(".Ldt-createAnnotation-keywords").append(templ);
    39     this.selector.find("#" + id).click(function(keyword) { return function() {
    39     this.selector.find("#" + id).click(function(keyword) { return function() {
    40       var contents = _this.selector.find(".Ldt-createAnnotation-Description").val();
    40       var contents = _this.selector.find(".Ldt-createAnnotation-Description").val();
    41       if (contents.indexOf(keyword) != -1) {
    41       if (contents.indexOf(keyword) != -1) {
    42         var newVal = contents.replace(keyword, "");        
    42         var newVal = contents.replace(" " + keyword, "");        
    43       } else {
    43       } else {
    44         var newVal = contents + keyword;      
    44         if (contents === "")
       
    45           var newVal = keyword;
       
    46         else
       
    47           var newVal = contents + " " + keyword;      
    45       }
    48       }
    46       
    49       
    47       _this.selector.find(".Ldt-createAnnotation-Description").val(newVal);
    50       _this.selector.find(".Ldt-createAnnotation-Description").val(newVal);
    48       // we use a custom event because there's no simple way to test for a js
    51       // we use a custom event because there's no simple way to test for a js
    49       // change in a textfield.
    52       // change in a textfield.
   141     }
   144     }
   142       // use namespaced events to be able to unbind them quickly and without unbinding
   145       // use namespaced events to be able to unbind them quickly and without unbinding
   143       // the other event handlers.
   146       // the other event handlers.
   144       textfield.bind("js_mod.tmp propertychange.tmp keyup.tmp input.tmp paste.tmp", IriSP.wrap(this, function() {
   147       textfield.bind("js_mod.tmp propertychange.tmp keyup.tmp input.tmp paste.tmp", IriSP.wrap(this, function() {
   145                       var contents = textfield.val();
   148                       var contents = textfield.val();
   146                       console.log(contents);
   149                       
   147                       if (contents !== "") {
   150                       if (contents !== "") {
   148                         this.selector.find(".Ldt-createAnnotation-errorMessage").hide();
   151                         this.selector.find(".Ldt-createAnnotation-errorMessage").hide();
   149                         textfield.css("background-color", "");
   152                         textfield.css("background-color", "");
   150                         textfield.unbind(".tmp");
   153                         textfield.unbind(".tmp");
   151                       }
   154                       }