1 | | jQuery(document).ready(function(a){a("#link_rel").attr("readonly","readonly");a("#linkxfndiv input").bind("click keyup",function(){var c=a("#me").is(":checked"),b="";a("input.valinp").each(function(){if(c){a(this).attr("disabled","disabled").parent().addClass("disabled")}else{a(this).removeAttr("disabled").parent().removeClass("disabled");if(a(this).is(":checked")&&a(this).val()!=""){b+=a(this).val()+" "}}});a("#link_rel").val((c)?"me":b.substr(0,b.length-1))})}); |
2 | | No newline at end of file |
| 1 | jQuery(document).ready( function($) { |
| 2 | var friendship = new Array("contact", "acquaintance", "friend"); |
| 3 | var geographical = new Array("co-resident", "neighbor"); |
| 4 | var family = new Array("child", "kin", "parent", "sibling", "spouse"); |
| 5 | |
| 6 | $('#link_rel').attr('readonly', ''); |
| 7 | $('#link_rel').bind('keyup', function() { |
| 8 | if($('#link_rel').val().substr($('#link_rel').val().length-1, $('#link_rel').val().length) == ' '){ |
| 9 | return; |
| 10 | } |
| 11 | |
| 12 | var oldWords = $('#link_rel').val().split(" "); |
| 13 | var unique = new Array() |
| 14 | for(var i = 0; i < oldWords.length; i++) { |
| 15 | if($.inArray(oldWords[i], unique) == -1) { |
| 16 | unique.push(oldWords[i]); |
| 17 | } |
| 18 | } |
| 19 | var count = oldWords.length - unique.length; |
| 20 | |
| 21 | oldWords = unique; |
| 22 | |
| 23 | if(count > 0) { |
| 24 | alert("The input field contains duplicates or none, these will be removed."); |
| 25 | |
| 26 | var output = ""; |
| 27 | for(var i = 0; i < oldWords.length; i++) { |
| 28 | output = output + oldWords[i] + " "; |
| 29 | } |
| 30 | |
| 31 | output = $.trim(output); // trim both sides cuz the user knows we will change sthg |
| 32 | |
| 33 | $('#link_rel').val( output ); |
| 34 | } |
| 35 | }); |
| 36 | |
| 37 | $('#linkxfndiv .form-table input').bind('click', function() { |
| 38 | var isMe = $('#me').is(':checked'), inputs = '', //toRemove = new Array(), |
| 39 | wasMe = ($('#link_rel').val() == "me"); |
| 40 | |
| 41 | if($('#link_rel').val() == "me") { |
| 42 | var oldWords = new Array(); |
| 43 | } |
| 44 | else { |
| 45 | var oldWords = $('#link_rel').val().split(" "); |
| 46 | } |
| 47 | |
| 48 | if (isMe) { |
| 49 | $('input.valinp').each( function() { |
| 50 | $(this).attr('disabled', 'disabled').parent().addClass('disabled'); |
| 51 | }); |
| 52 | } |
| 53 | else { |
| 54 | $('input.valinp').each( function() { |
| 55 | $(this).removeAttr('disabled').parent().removeClass('disabled'); |
| 56 | }); |
| 57 | |
| 58 | if(wasMe) { |
| 59 | // trigger the code below for every field to rebuild input |
| 60 | $('input.valinp').each( function() { |
| 61 | oldWords = updateField($(this), oldWords) ; |
| 62 | }); |
| 63 | } |
| 64 | else { |
| 65 | // execute only for clicked field |
| 66 | oldWords = updateField($(this), oldWords) ; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | var output = ""; |
| 71 | for(var i = 0; i < oldWords.length; i++) { |
| 72 | output = output + oldWords[i] + " "; |
| 73 | } |
| 74 | output = $.trim(output); |
| 75 | |
| 76 | $('#link_rel').val( (isMe) ? 'me' : output ); |
| 77 | }); |
| 78 | |
| 79 | function updateField(field, oldWords) { |
| 80 | if ( field.is(':checked') && field.val() != '') { |
| 81 | // we know that this value should be added, so check if its there |
| 82 | |
| 83 | if($.inArray(field.val(), oldWords) == -1) { // its not |
| 84 | // determine the group |
| 85 | var group = determineGroup(field.val()); |
| 86 | |
| 87 | // check if any alternative there to remove |
| 88 | if(group != null) { |
| 89 | for(var i = 0; i < group.length; i++) { |
| 90 | oldWords = jQuery.grep(oldWords, function(value) { |
| 91 | return value != group[i]; |
| 92 | }); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | oldWords.push(field.val()); |
| 97 | } |
| 98 | } |
| 99 | else if ( field.is(':checked') && field.val() == '') { // its a none that was selected, so remove any alternatives, it will remove duplicates as well |
| 100 | // determine the group |
| 101 | var group = determineGroup(field.get(0).name); |
| 102 | |
| 103 | // check if any alternative present to remove |
| 104 | if(group != null) { |
| 105 | for(var i = 0; i < group.length; i++) { |
| 106 | oldWords = jQuery.grep(oldWords, function(value) { |
| 107 | return value != group[i]; |
| 108 | }); |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | else if ( !field.is(':checked') && field.get(0).type === "checkbox") { |
| 113 | // its a checkbox not selected so check it |
| 114 | while($.inArray(field.val(), oldWords) != -1) { // it is, while lus to remove several duplicates |
| 115 | oldWords.splice($.inArray(field.val(), oldWords),1); // remove it |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | return oldWords; |
| 120 | } |
| 121 | |
| 122 | function removeDuplicates(current) { |
| 123 | var unique = new Array() |
| 124 | for(var i = 0; i < current.length; i++) { |
| 125 | if($.inArray(current[i], unique) == -1) { |
| 126 | unique.push(current[i]); |
| 127 | } |
| 128 | } |
| 129 | return unique; |
| 130 | } |
| 131 | |
| 132 | function determineGroup(field) { |
| 133 | // determine the group |
| 134 | var group = null; |
| 135 | if($.inArray(field, friendship) != -1 || field == "friendship") { |
| 136 | group = friendship; |
| 137 | } |
| 138 | else if($.inArray(field, geographical) != -1 || field == "geographical") { |
| 139 | group = geographical; |
| 140 | } |
| 141 | else if($.inArray(field, family) != -1 || field == "family") { |
| 142 | group = family; |
| 143 | } |
| 144 | return group; |
| 145 | } |
| 146 | });jQuery(document).ready( function($) { |
| 147 | var friendship = new Array("contact", "acquaintance", "friend"); |
| 148 | var geographical = new Array("co-resident", "neighbor"); |
| 149 | var family = new Array("child", "kin", "parent", "sibling", "spouse"); |
| 150 | |
| 151 | $('#link_rel').attr('readonly', ''); |
| 152 | $('#link_rel').bind('keyup', function() { |
| 153 | if($('#link_rel').val().substr($('#link_rel').val().length-1, $('#link_rel').val().length) == ' '){ |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | var oldWords = $('#link_rel').val().split(" "); |
| 158 | var unique = new Array() |
| 159 | for(var i = 0; i < oldWords.length; i++) { |
| 160 | if($.inArray(oldWords[i], unique) == -1) { |
| 161 | unique.push(oldWords[i]); |
| 162 | } |
| 163 | } |
| 164 | var count = oldWords.length - unique.length; |
| 165 | |
| 166 | oldWords = unique; |
| 167 | |
| 168 | if(count > 0) { |
| 169 | alert("The input field contains duplicates or none, these will be removed."); |
| 170 | |
| 171 | var output = ""; |
| 172 | for(var i = 0; i < oldWords.length; i++) { |
| 173 | output = output + oldWords[i] + " "; |
| 174 | } |
| 175 | |
| 176 | output = $.trim(output); // trim both sides cuz the user knows we will change sthg |
| 177 | |
| 178 | $('#link_rel').val( output ); |
| 179 | } |
| 180 | }); |
| 181 | |
| 182 | $('#linkxfndiv .form-table input').bind('click', function() { |
| 183 | var isMe = $('#me').is(':checked'), inputs = '', //toRemove = new Array(), |
| 184 | wasMe = ($('#link_rel').val() == "me"); |
| 185 | |
| 186 | if($('#link_rel').val() == "me") { |
| 187 | var oldWords = new Array(); |
| 188 | } |
| 189 | else { |
| 190 | var oldWords = $('#link_rel').val().split(" "); |
| 191 | } |
| 192 | |
| 193 | if (isMe) { |
| 194 | $('input.valinp').each( function() { |
| 195 | $(this).attr('disabled', 'disabled').parent().addClass('disabled'); |
| 196 | }); |
| 197 | } |
| 198 | else { |
| 199 | $('input.valinp').each( function() { |
| 200 | $(this).removeAttr('disabled').parent().removeClass('disabled'); |
| 201 | }); |
| 202 | |
| 203 | if(wasMe) { |
| 204 | // trigger the code below for every field to rebuild input |
| 205 | $('input.valinp').each( function() { |
| 206 | oldWords = updateField($(this), oldWords) ; |
| 207 | }); |
| 208 | } |
| 209 | else { |
| 210 | // execute only for clicked field |
| 211 | oldWords = updateField($(this), oldWords) ; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | var output = ""; |
| 216 | for(var i = 0; i < oldWords.length; i++) { |
| 217 | output = output + oldWords[i] + " "; |
| 218 | } |
| 219 | output = $.trim(output); |
| 220 | |
| 221 | $('#link_rel').val( (isMe) ? 'me' : output ); |
| 222 | }); |
| 223 | |
| 224 | function updateField(field, oldWords) { |
| 225 | if ( field.is(':checked') && field.val() != '') { |
| 226 | // we know that this value should be added, so check if its there |
| 227 | |
| 228 | if($.inArray(field.val(), oldWords) == -1) { // its not |
| 229 | // determine the group |
| 230 | var group = determineGroup(field.val()); |
| 231 | |
| 232 | // check if any alternative there to remove |
| 233 | if(group != null) { |
| 234 | for(var i = 0; i < group.length; i++) { |
| 235 | oldWords = jQuery.grep(oldWords, function(value) { |
| 236 | return value != group[i]; |
| 237 | }); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | oldWords.push(field.val()); |
| 242 | } |
| 243 | } |
| 244 | else if ( field.is(':checked') && field.val() == '') { // its a none that was selected, so remove any alternatives, it will remove duplicates as well |
| 245 | // determine the group |
| 246 | var group = determineGroup(field.get(0).name); |
| 247 | |
| 248 | // check if any alternative present to remove |
| 249 | if(group != null) { |
| 250 | for(var i = 0; i < group.length; i++) { |
| 251 | oldWords = jQuery.grep(oldWords, function(value) { |
| 252 | return value != group[i]; |
| 253 | }); |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | else if ( !field.is(':checked') && field.get(0).type === "checkbox") { |
| 258 | // its a checkbox not selected so check it |
| 259 | while($.inArray(field.val(), oldWords) != -1) { // it is, while lus to remove several duplicates |
| 260 | oldWords.splice($.inArray(field.val(), oldWords),1); // remove it |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | return oldWords; |
| 265 | } |
| 266 | |
| 267 | function removeDuplicates(current) { |
| 268 | var unique = new Array() |
| 269 | for(var i = 0; i < current.length; i++) { |
| 270 | if($.inArray(current[i], unique) == -1) { |
| 271 | unique.push(current[i]); |
| 272 | } |
| 273 | } |
| 274 | return unique; |
| 275 | } |
| 276 | |
| 277 | function determineGroup(field) { |
| 278 | // determine the group |
| 279 | var group = null; |
| 280 | if($.inArray(field, friendship) != -1 || field == "friendship") { |
| 281 | group = friendship; |
| 282 | } |
| 283 | else if($.inArray(field, geographical) != -1 || field == "geographical") { |
| 284 | group = geographical; |
| 285 | } |
| 286 | else if($.inArray(field, family) != -1 || field == "family") { |
| 287 | group = family; |
| 288 | } |
| 289 | return group; |
| 290 | } |
| 291 | }); |
| 292 | No newline at end of file |