1

I am trying to change my profile picture via ajax.

I used views to display my user profile picture in a block. This works Perfect. I am then using the avatar uploader module to change my user profile picture. This module is exactly what I want because it also crops my photos. The problem is, this works, but only if I am on the user edit page. I get the ajax uploader if I click on my profile picture that is displayed using views, but only on the user edit page.

Is there any way to get this module to work regardless of what page I am on?

Thanks.

1

Firstly, Check avatar_uploader.js file, the default selector is '.profile .user-picture a', if you want to use this for other profile img, please change the selector Drupal.settings.avatar_selector

Drupal.behaviors.avatar_uploader = {
    attach: function(context) {
        if (Drupal.settings.avatar_uid) {
            Drupal.settings.avatar_selector = Drupal.settings.avatar_selector || '.profile .user-picture a';
        var el = jQuery(Drupal.settings.avatar_selector);
        au.attach(el, Drupal.settings.avatar_uid, Drupal.t('Change avatar'));
         }
     }
}

Second, Check "avatar_uploader.module".

These code is to use uploader only in 'user' page in order to reduce js for browser, so you can change here

hook_init

$params = array('avatar_panel_id' => UPLOADER_PANEL_ID);
    if ($user->uid) {
        if (arg(0) == 'user' || (arg(0) == 'user' && arg(1) == $user->uid)) {
           $params['avatar_uid'] = $user->uid;
        }
    }

https://www.drupal.org/node/2469945

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.