1 2/* $Id: core.js 9984 2013-03-20 00:00:04Z john $ */ 3 4 5 6(function() { // START NAMESPACE 7var $ = 'id' in document ? document.id : window.$; 8 9 10 11en4.user = { 12 13 viewer : { 14 type : false, 15 id : false 16 }, 17 18 attachEmailTaken : function(element, callback) 19 { 20 var bind = this; 21 element.addEvent('blur', function(){ 22 bind.checkEmailTaken(element.value, callback); 23 }); 24 25 /* 26 var lastElementValue = element.value; 27 (function(){ 28 if( element.value != lastElementValue ) 29 { 30 31 lastElementValue = element.value; 32 } 33 }).periodical(500, this); 34 */ 35 }, 36 37 attachUsernameTaken : function(element, callback) 38 { 39 var bind = this; 40 element.addEvent('blur', function(){ 41 bind.checkUsernameTaken(element.value, callback); 42 }); 43 44 /* 45 var lastElementValue = element.value; 46 (function(){ 47 if( element.value != lastElementValue ) 48 { 49 bind.checkUsernameTaken(element.value, callback); 50 lastElementValue = element.value; 51 } 52 }).periodical(500, this); 53 */ 54 }, 55 56 checkEmailTaken : function(email, callback) 57 { 58 en4.core.request.send(new Request.JSON({ 59 url : en4.core.baseUrl + 'user/signup/taken', 60 data : { 61 format : 'json', 62 email : email 63 }, 64 onSuccess : function(responseObject) 65 { 66 if( $type(responseObject.taken) ){ 67 callback(responseObject.taken); 68 } 69 } 70 })); 71 72 return this; 73 }, 74 75 checkUsernameTaken : function(username) 76 { 77 en4.core.request.send(new Request.JSON({ 78 url : en4.core.baseUrl + 'user/signup/taken', 79 data : { 80 format : 'json', 81 username : username 82 }, 83 onSuccess : function(responseObject) 84 { 85 if( $type(responseObject.taken) ){ 86 callback(responseObject.taken); 87 } 88 } 89 })); 90 91 return this; 92 }, 93 94 clearStatus : function() { 95 var request = new Request.JSON({ 96 url : en4.core.baseUrl + 'user/edit/clear-status', 97 method : 'post', 98 data : { 99 format : 'json' 100 } 101 }); 102 request.send(); 103 if( $('user_profile_status_container') ) { 104 $('user_profile_status_container').empty(); 105 } 106 return request; 107 }, 108 109 buildFieldPrivacySelector : function(elements, privacyExemptFields) { 110 var idEx = {}; 111 privacyExemptFields = typeof (privacyExemptFields) !== 'object' ? {} : privacyExemptFields; 112 // Clear when body click, if not inside selector 113 document.addEvent('click', function(event) { 114 if( event.target.hasClass('field-privacy-selector') ) { 115 return; 116 } else if( event.target.getParent('.field-privacy-selector') ) { 117 return; 118 } else { 119 $$('.field-privacy-selector').removeClass('active'); 120 } 121 }); 122 123 // Register selectors 124 elements.each(function(el) { 125 if( el.get('tag') == 'span' ) { 126 return; 127 } 128 var fuid = el.get('id'); 129 var tmp; 130 if( (tmp = fuid.match(/^\d+_\d+_\d+/)) ) { 131 fuid = tmp[0]; 132 } 133 var id = el.get('data-field-id'); 134 if( id in idEx ) { 135 return; 136 } 137 if( Object.values(privacyExemptFields).indexOf(parseInt(id)) > -1 ) { 138 return; 139 } 140 idEx[id] = true; 141 var wrapperEl = el.getParent('.form-wrapper'); 142 var privacyValue = el.get('data-privacy'); 143 144 var selector = new Element('div', { 145 'class' : 'field-privacy-selector', 146 'data-privacy' : privacyValue || 'everyone', 147 'html' : '\ 148 <span class="icon"></span>\n\ 149 <span class="caret"></span>\n\ 150 <ul>\n\ 151 <li data-value="everyone" class="field-privacy-option-everyone"><span class="icon"></span><span class="text">' 152 + en4.core.language.translate('Everyone') + '</span></li>\n\ 153 <li data-value="registered" class="field-privacy-option-registered"><span class="icon"></span><span class="text">' 154 + en4.core.language.translate('All Members') + '</span></li>\n\ 155 <li data-value="friends" class="field-privacy-option-friends"><span class="icon"></span><span class="text">' 156 + en4.core.language.translate('Friends') + '</span></li>\n\ 157 <li data-value="self" class="field-privacy-option-self"><span class="icon"></span><span class="text">' 158 + en4.core.language.translate('Only Me') + '</span></li>\n\ 159 </ul>\n\ 160 <input type="hidden" name="privacy[' + fuid + ']" />' 161 }); 162 selector.inject(wrapperEl); 163 selector.addEvent('click', function(event) { 164 var prevState = selector.hasClass('active'); 165 $$('.field-privacy-selector').removeClass('active'); 166 if( !prevState ) { 167 selector.addClass('active'); 168 } 169 }); 170 selector.getElements('li').addEvent('click', function(event) { 171 var el = event.target; 172 if( el.get('tag') != 'li' ) { 173 el = el.getParent(); 174 } 175 var value = el.get('data-value'); 176 selector.getElement('input').set('value', value); 177 selector.getElement('.active').removeClass('active'); 178 el.addClass('active'); 179 selector.set('data-privacy', value); 180 }) 181 selector.getElement('*[data-value="' + (privacyValue || 'everyone') + '"]').addClass('active'); 182 selector.getElement('input').set('value', privacyValue || 'everyone'); 183 }); 184 } 185 186}; 187 188en4.user.friends = { 189 190 refreshLists : function(){ 191 192 }, 193
194 addToList : function(list_id, user_id){ 195 var request = new Request.JSON({ 196 url : en4.core.baseUrl + 'user/friends/list-add', 197 data : { 198 format : 'json', 199 friend_id : user_id, 200 list_id : list_id 201 } 202 }); 203 request.send(); 204 return request; 205 206 /* 207 $('profile_friends_lists_menu_' + user_id).style.display = 'none'; 208 209 var bind = this; 210 en4.core.request.send(new Request.JSON({ 211 url : en4.core.baseUrl + 'user/friends/list-add', 212 data : { 213 format : 'json', 214 friend_id : user_id, 215 list_id : list_id 216 } 217 }), { 218 'element' : $('user_friend_' + user_id) 219 }); 220 221 return this; 222 */ 223 }, 224 225 removeFromList : function(list_id, user_id){ 226 var request = new Request.JSON({ 227 url : en4.core.baseUrl + 'user/friends/list-remove', 228 data : { 229 format : 'json', 230 friend_id : user_id, 231 list_id : list_id 232 } 233 }); 234 request.send(); 235 return request; 236 /* 237 var bind = this; 238 en4.core.request.send(new Request.JSON({ 239 url : en4.core.baseUrl + 'user/friends/list-remove', 240 data : { 241 format : 'json', 242 friend_id : user_id, 243 list_id : list_id 244 } 245 }), { 246 'element' : $('user_friend_' + user_id) 247 }); 248 249 return this; 250 */ 251 }, 252 253 createList : function(title, user_id){ 254 var request = new Request.JSON({ 255 url : en4.core.baseUrl + 'user/friends/list-create', 256 data : { 257 format : 'json', 258 friend_id : user_id, 259 title : title 260 } 261 }); 262 request.send(); 263 return request; 264 265 /* 266 $('profile_friends_lists_menu_' + user_id).style.display = 'none'; 267 var bind = this; 268 en4.core.request.send(new Request.JSON({ 269 url : en4.core.baseUrl + 'user/friends/list-create', 270 data : { 271 format : 'json', 272 friend_id : user_id, 273 list_title : title 274 } 275 }), { 276 'element' : $('user_friend_' + user_id) 277 }); 278 279 return this; 280 */ 281 }, 282 283 deleteList : function(list_id){ 284 285 var bind = this; 286 en4.core.request.send(new Request.JSON({ 287 url : en4.core.baseUrl + 'user/friends/list-delete', 288 data : { 289 format : 'json', 290 user_id : en4.user.viewer.id, 291 list_id : list_id 292 } 293 })); 294 295 return this; 296 }, 297 298 299 showMenu : function(user_id){ 300 $('profile_friends_lists_menu_' + user_id).style.visibility = 'visible'; 301 $('friends_lists_menu_input_' + user_id).focus(); 302 $('friends_lists_menu_input_' + user_id).select(); 303 }, 304 305 hideMenu : function(user_id){ 306 $('profile_friends_lists_menu_' + user_id).style.visibility = 'hidden'; 307 }, 308 309 clearAddList : function(user_id){ 310 $('friends_lists_menu_input_' + user_id).value = ""; 311 } 312 313}; 314 315 316 317})(); // END NAMESPACE
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.