var previousPositionOfCover = scriptJquery('#user_cover_id').css('top');
//Reposition Photo
AttachEventListerSE('click', '#user_main_photo_reposition', function() {
scriptJquery('.user_cover_reposition_btns').show();
scriptJquery('.user_cover_fade').hide();
scriptJquery('#user_cover_change').hide();
// scriptJquery('.user_cover_inner').hide();
scriptJquery('#user_cover_id').dragncrop({
instruction: true,
instructionText: 'Drag to Reposition'
});
});
AttachEventListerSE('click', '#cancelreposition', function() {
scriptJquery('.user_cover_reposition_btns').hide();
scriptJquery('#user_cover_id').css('top', previousPositionOfCover);
scriptJquery('.user_cover_fade').show();
scriptJquery('#user_cover_change').show();
// scriptJquery('.user_cover_inner').show();
scriptJquery("#user_cover_id").dragncrop('destroy');
if(typeof uploadCoverPhoto != 'undefined') {
scriptJquery('#user_cover_id').attr('src', uploadCoverPhoto);
uploadCoverPhoto = undefined;
}
});
AttachEventListerSE('click', '#savereposition', function() {
var sendposition = scriptJquery('#user_cover_id').css('top');
if(typeof uploadCoverPhoto != 'undefined') {
uploadCoverPhoto = undefined;
uploadImageAfterSelect(sendposition);
return;
}
var sendposition = scriptJquery('#user_cover_id').css('top');
scriptJquery('#user_cover_photo_loading').show();
var uploadURL = en4.core.baseUrl + 'user/coverphoto/reposition-cover/user_id/56052';
var formData = new FormData();
formData.append('position', sendposition);
var jqXHR = scriptJquery.ajax({
url: uploadURL,
type: "POST",
contentType: false,
processData: false,
data: formData,
cache: false,
success: function(response) {
response = scriptJquery.parseJSON(response);
if (response.status == 1) {
previousPositionOfCover = sendposition;
scriptJquery('.user_cover_reposition_btns').hide();
scriptJquery("#user_cover_id").dragncrop('destroy');
scriptJquery('.user_cover_fade').show();
scriptJquery('#user_cover_change').show();
} else {
alert('Something went wrong, please try again later.');
}
scriptJquery('#user_cover_photo_loading').hide();
//silence
}
});
});
//Upload Main User Photo Code
function uploadFileToServerMain(files) {
scriptJquery('.user_cover_main_photo').append('');
var formData = new FormData();
formData.append('webcam', files);
uploadURL = en4.core.baseUrl + 'user/coverphoto/upload-main/user_id/56052';
var jqXHR = scriptJquery.ajax({
url: uploadURL,
type: "POST",
contentType: false,
processData: false,
cache: false,
data: formData,
success: function(response) {
response = scriptJquery.parseJSON(response);
scriptJquery('#uploadFileMainCoverPhoto').val('');
scriptJquery('#user_cover_loading_main').remove();
scriptJquery('#user_profile_photo').removeClass('bg_item_nophoto');
scriptJquery('#user_profile_photo').css("background-image", "url(" + response.src + ")");
scriptJquery('#change_main_cvr_pht').html('' + en4.core.language.translate('Change Cover Photo'));
scriptJquery('#user_main_photo_i').css('display', 'block !important');
loadAjaxContentApp(window.location.href,false,"full");
}
});
}
function uploadFileMainCoverPhoto(input) {
var url = input.value;
var ext = url.substring(url.lastIndexOf('.') + 1).toLowerCase();
if (input.files && input.files[0] && (ext == "png" || ext == "jpeg" || ext == "jpg" || ext == 'PNG' || ext == 'JPEG' || ext == 'JPG' || ext == 'gif' || ext == 'GIF' || ext == "webp" || ext == 'webp')) {
uploadFileToServerMain(input.files[0]);
} else {
//Silence
}
}
AttachEventListerSE('click', '#change_main_cvr_pht', function() {
document.getElementById('uploadFileMainCoverPhoto').click();
});
//Upload Cover Photo Code
en4.core.runonce.add(function() {
scriptJquery('').appendTo('#append-script-data');
});
AttachEventListerSE('click', '#uploadCoverPhoto', function() {
document.getElementById('uploadFileUserCoverPhoto').click();
});
var uploadCoverPhoto;
function readCoverPhotoImageUrl(input) {
var url = input.files[0].name;
var ext = url.substring(url.lastIndexOf('.') + 1).toLowerCase();
if ((ext == "png" || ext == "jpeg" || ext == "jpg" || ext == 'PNG' || ext == 'JPEG' || ext == 'JPG' || ext == 'gif' || ext == 'GIF' || ext == "webp")) {
var reader = new FileReader();
reader.onload = function (e) {
uploadCoverPhoto = scriptJquery('#user_cover_id').attr('src');
if (scriptJquery('#user_cover_video_id').length)
scriptJquery('#user_cover_video_id').hide();
scriptJquery('#user_cover_id').show();
scriptJquery('#user_cover_id').attr('src', e.target.result);
scriptJquery('#user_cover_default').hide();
//scriptJquery('#uploadCoverPhoto').html('
' + en4.core.language.translate('Change Cover Photo'));
//scriptJquery('#removeCover').css('display', 'flex');
//scriptJquery('#user_main_photo_reposition').css('display', 'flex');
scriptJquery('#user_cover_photo_loading').hide();
//scriptJquery('#uploadFileUserCoverPhoto').val('');
scriptJquery('#user_main_photo_reposition').trigger('click');
}
reader.readAsDataURL(input.files[0]);
}
}
function uploadImageAfterSelect(sendposition) {
var formData = new FormData();
formData.append('position', sendposition ? sendposition : '');
formData.append('webcam', scriptJquery('#uploadFileUserCoverPhoto')[0].files[0]);
formData.append('user_id', '56052');
scriptJquery('#user_cover_photo_loading').show();
scriptJquery.ajax({
xhr: function() {
var xhrobj = scriptJquery.ajaxSettings.xhr();
if (xhrobj.upload) {
xhrobj.upload.addEventListener('progress', function(event) {
var percent = 0;
var position = event.loaded || event.position;
var total = event.total;
if (event.lengthComputable) {
percent = Math.ceil(position / total * 100);
}
//Set progress
}, false);
}
return xhrobj;
},
url: en4.core.baseUrl + 'user/coverphoto/edit-coverphoto/',
type: "POST",
contentType: false,
processData: false,
cache: false,
data: formData,
success: function(response) {
text = JSON.parse(response);
if (text.status == 'true') {
if (text.src != '') {
if (scriptJquery('#user_cover_video_id').length)
scriptJquery('#user_cover_video_id').hide();
scriptJquery('#user_cover_id').show();
scriptJquery('#user_cover_id').attr('src', text.src);
}
scriptJquery('#user_cover_default').hide();
scriptJquery('#uploadCoverPhoto').html('
' + en4.core.language.translate('Change Cover Photo'));
scriptJquery('#removeCover').css('display', 'flex');
scriptJquery('#user_main_photo_reposition').css('display', 'flex');
previousPositionOfCover = sendposition;
scriptJquery('.user_cover_reposition_btns').hide();
scriptJquery("#user_cover_id").dragncrop('destroy');
scriptJquery('.user_cover_fade').show();
scriptJquery('#user_cover_change').show();
}
scriptJquery('#user_cover_photo_loading').hide();
scriptJquery('#uploadFileUserCoverPhoto').val('');
loadAjaxContentApp(window.location.href,false,"full");
}
});
}
function removeProfilePhoto() {
//scriptJquery('#user_main_photo_i').click(function() {
scriptJquery('.user_cover_main_photo').append('
');
var user_id = '56052';
uploadURL = en4.core.baseUrl + 'user/coverphoto/remove-main/user_id/' + user_id;
var jqXHR = scriptJquery.ajax({
url: uploadURL,
type: "POST",
contentType: false,
processData: false,
cache: false,
success: function(response) {
scriptJquery('#change_main_cvr_pht').html('
' + en4.core.language.translate('Add User Photo'));
response = scriptJquery.parseJSON(response);
scriptJquery('#user_profile_photo').css("background-image", "url('')");
scriptJquery('#user_profile_photo').addClass('bg_item_nophoto');
scriptJquery('#user_cover_loading_main').remove();
scriptJquery('#user_main_photo_i').hide();
//silence
loadAjaxContentApp(window.location.href,false,"full");
}
});
//});
}
function removeCoverPhoto() {
scriptJquery('#removeCover').css('display', 'none');
//scriptJquery('#user_cover_id').attr('src', '' );
scriptJquery('#user_cover_photo_loading').show();
//scriptJquery('#user_cover_default').show();
var user_id = '56052';
uploadURL = en4.core.baseUrl + 'user/coverphoto/remove-cover/user_id/' + user_id;
var jqXHR = scriptJquery.ajax({
url: uploadURL,
type: "POST",
contentType: false,
processData: false,
cache: false,
success: function(response) {
var response = scriptJquery.parseJSON(response);
scriptJquery('#user_cover_photo_loading').hide();
scriptJquery('#uploadCoverPhoto').html('
' + en4.core.language.translate('Add Cover Photo'));
scriptJquery('#user_main_photo_reposition').css('display', 'none');
scriptJquery('#user_cover_id').css('top', '0');
//update defaultphoto if available from admin.
if (response.src) {
scriptJquery('#usercovevideo_cover_video_id').hide();
scriptJquery('#user_cover_id').show();
scriptJquery('#user_cover_id').attr('src', response.src);
} else {
scriptJquery('#usercovevideo_cover_video_id').hide();
scriptJquery('#user_cover_id').show();
scriptJquery('#user_cover_id').attr('src', '');
}
loadAjaxContentApp(window.location.href,false,"full");
}
});
}
function hideCoverPhotoUpload() {
canPaginatePageNumber = 1;
scriptJquery('#coverphoto_popup_cam_upload').hide();
scriptJquery('#coverphoto_popup_existing_upload').hide();
if (typeof Webcam != 'undefined') {
scriptJquery('.slimScrollDiv').remove();
scriptJquery('.user_photo_update_popup_content').html('

');
}
}
AttachEventListerSE('click', function(event) {
if (event.target.id == 'change_coverphoto_profile_txt' || event.target.id == 'cover_change_btn_i' || event.target.id == 'cover_change_btn') {
scriptJquery('#user_cover_option_main_id').removeClass('active')
if (scriptJquery('#user_cover_change').hasClass('active'))
scriptJquery('#user_cover_change').removeClass('active');
else
scriptJquery('#user_cover_change').addClass('active');
} else if (event.target.id == 'change_main_txt' || event.target.id == 'change_main_btn' || event.target.id == 'change_main_i') {
console.log('tyes');
scriptJquery('#user_cover_change').removeClass('active');
if (scriptJquery('#user_cover_option_main_id').hasClass('active'))
scriptJquery('#user_cover_option_main_id').removeClass('active');
else
scriptJquery('#user_cover_option_main_id').addClass('active');
} else {
scriptJquery('#user_cover_change').removeClass('active')
scriptJquery('#user_cover_option_main_id').removeClass('active')
}
});
AttachEventListerSE('click', '#fromCoverPhotoExistingAlbum', function() {
scriptJquery('#coverphoto_popup_existing_upload').show();
existingCoverPhotosGet();
});
var canPaginatePageNumber = 1;
function existingCoverPhotosGet() {
scriptJquery('#coverphoto_profile_existing_img').show();
var URL = en4.core.baseUrl + 'user/coverphoto/existing-photos/';
scriptJquery.ajax({
method: 'post',
'url': URL,
'data': {
format: 'html',
cover: 'cover',
page: canPaginatePageNumber,
is_ajax: 1
},
success: function(responseHTML) {
scriptJquery('#coverphoto_existing_data').append(responseHTML);
scriptJquery('#coverphoto_existing_data').slimscroll({
height: 'auto',
alwaysVisible: true,
color: '#000',
railOpacity: '0.5',
disableFadeOut: true,
});
scriptJquery('#coverphoto_existing_data').slimScroll().bind('slimscroll', function(event, pos) {
if (canPaginateExistingPhotos == '1' && pos == 'bottom' && scriptJquery('#coverphoto_profile_existing_img').css('display') != 'block') {
scriptJquery('#coverphoto_profile_existing_img').css('position', 'absolute').css('width', '100%').css('bottom', '5px');
existingCoverPhotosGet();
}
});
scriptJquery('#coverphoto_profile_existing_img').hide();
}
});
}
AttachEventListerSE('click', 'a[id^="user_cover_existing_album_see_more_"]', function(event) {
event.preventDefault();
var thatObject = this;
scriptJquery(thatObject).parent().hide();
var id = scriptJquery(this).attr('id').match(/\d+/)[0];
var pageNum = parseInt(scriptJquery(this).attr('data-src'), 10);
scriptJquery('#user_existing_album_see_more_loading_' + id).show();
if (pageNum == 0) {
scriptJquery('#user_existing_album_see_more_page_' + id).remove();
return;
}
var URL = en4.core.baseUrl + 'user/coverphoto/existing-albumphotos/';
scriptJquery.ajax({
method: 'post',
'url': URL,
'data': {
format: 'html',
page: pageNum + 1,
id: id,
cover: 'cover',
},
success: function(responseHTML) {
scriptJquery('#user_photo_content_' + id).append(responseHTML);
var dataSrc = scriptJquery('#user_existing_album_see_more_page_' + id).html();
scriptJquery('#user_existing_album_see_more_' + id).attr('data-src', dataSrc);
scriptJquery('#user_existing_album_see_more_page_' + id).remove();
if (dataSrc == 0)
scriptJquery('#user_existing_album_see_more_' + id).parent().remove();
else
scriptJquery(thatObject).parent().show();
scriptJquery('#user_existing_album_see_more_loading_' + id).hide();
}
});
});
AttachEventListerSE('click', 'a[id^="user_cover_upload_existing_photos_"]', function(event) {
event.preventDefault();
var id = scriptJquery(this).attr('id').match(/\d+/)[0];
if (!id)
return;
scriptJquery('#user_cover_photo_loading').show();
hideCoverPhotoUpload();
var URL = en4.core.baseUrl + 'user/coverphoto/uploadexistingcoverphoto/';
scriptJquery.ajax({
method: 'post',
'url': URL,
'data': {
format: 'html',
id: id,
cover: 'cover',
user_id: '56052'
},
success: function(responseHTML) {
text = JSON.parse(responseHTML);
if (text.status == 'true') {
if (text.src != '') {
if (scriptJquery('#user_cover_video_id').length)
scriptJquery('#user_cover_video_id').hide();
scriptJquery('#user_cover_id').show();
scriptJquery('#user_cover_id').attr('src', text.src);
}
scriptJquery('#user_cover_default').hide();
scriptJquery('#uploadCoverPhoto').html('
' + en4.core.language.translate('Change Cover Photo'));
scriptJquery('#removeCover').css('display', 'flex');
scriptJquery('#user_main_photo_reposition').css('display', 'flex');
scriptJquery('#user_main_photo_reposition').trigger('click');
}
scriptJquery('#user_cover_photo_loading').hide();
scriptJquery('#uploadFileUserCoverPhoto').val('');
}
});
});