Created
February 5, 2013 18:01
-
-
Save gbasov/4716314 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function($) { | |
var | |
$body = $('body'), | |
$formStart = $('.b-formStart'), | |
$formStartOne = $formStart.find('.column_one'), | |
$formStartTwo = $formStart.find('.column_two'); | |
$(function() { | |
var ids_hash = {}; | |
$('[data-replace=name], [data-replace=image]').each(function(i, el) { | |
ids_hash[$(el).data('id')] = true; | |
}); | |
var ids = []; | |
for (var i in ids_hash) | |
{ | |
if (ids_hash.hasOwnProperty(i)) | |
{ | |
ids.push(i); | |
} | |
} | |
if (window.social == 'vk') | |
{ | |
VK.init(function() { | |
if (ids.length > 0) | |
{ | |
ids = ids.join(','); | |
VK.api('users.get', { uids: ids, fields: 'uid,first_name,last_name,photo_medium_rec' }, function(response) { | |
for (var i in response.response) | |
{ | |
var data = response.response[i]; | |
$('[data-id=' + data.uid + ']').each(function(i, el) { | |
if ($(el).data('replace') == 'name') | |
{ | |
$(el).html( data.first_name + ' ' + data.last_name ); | |
} | |
else if ($(el).data('replace') == 'image') | |
{ | |
$(el).attr('src', data.photo_medium_rec); | |
} | |
}); | |
} | |
}); | |
} | |
VK.callMethod('resizeWindow', 810, $('body').height() > 800 ? $('body').height() : 800); | |
VK.callMethod('scrollSubscribe'); | |
VK.addCallback('onScroll', function(scrollTop, height) { | |
window.parent_scroll = scrollTop; | |
window.parent_height = height; | |
$('.i-popup').css('top', (window.parent_scroll + 10) + 'px'); | |
}); | |
$('.share').click(function(ev) { | |
ev.preventDefault(); | |
var _this = this; | |
$(_this).html('Загрузка…'); | |
var participant_id = $(this).data('id'); | |
VK.api('photos.getWallUploadServer', {}, function(res) { | |
var upload_url = res.response.upload_url; | |
$.ajax({ | |
url: window.url_base + '/main/vkUploadFile?social=' + window.social, | |
type: 'post', | |
dataType: 'json', | |
data: { id: participant_id, url: upload_url }, | |
success: function(res) | |
{ | |
if (!res.photo) | |
{ | |
if (typeof window.share_on_load == 'undefined') | |
alert('Произошла ошибка во время публикации. Попробуйте опубликовать фотографию позднее.'); | |
return false; | |
} | |
VK.api('photos.saveWallPhoto', res, function(res) { | |
if (!res.response) | |
{ | |
if (typeof window.share_on_load == 'undefined') | |
alert('Произошла ошибка во время публикации. Попробуйте опубликовать фотографию позднее.'); | |
return false; | |
} | |
VK.api('wall.post', { attachments: res.response[0].id + ',http://vk.com/app3152171', message: 'Я участвую в конкурсе «Выиграй с Шараповой», поддержи меня лайком!' }, function() { | |
$(_this).html('Поделиться'); | |
}); | |
}); | |
} | |
}); | |
}); | |
return false; | |
}); | |
if (typeof window.share_on_load != 'undefined') | |
{ | |
$('.share').trigger('click'); | |
} | |
$('.accept-photo').click(function(ev) { | |
var _this = $(this); | |
VK.api('users.get', { uids: window.social_id, fields: 'first_name,last_name' }, function(response) { | |
var username = response.response[0].first_name + ' ' + response.response[0].last_name; | |
var form = $('<form method="post" action=""></form>'); | |
form.attr('action', $(_this).attr('href')); | |
var input = $('<input type="hidden" name="username" value="" />'); | |
form.append(input); | |
$('body').append(form); | |
$(input).val(username); | |
form.submit(); | |
}); | |
return false; | |
}); | |
$('.b-photo__tarea .ok').click(function() { | |
var form = $(this).parents('form'); | |
if (form.find('input[name=username]').length == 0) | |
{ | |
form.submit(); | |
return false; | |
} | |
VK.api('users.get', { uids: window.social_id, fields: 'first_name,last_name' }, function(response) { | |
var username = response.response[0].first_name + ' ' + response.response[0].last_name; | |
form.find('input[name=username]').val(username); | |
form.submit(); | |
}); | |
return false; | |
}); | |
}); | |
} | |
else | |
{ | |
FB.init({ | |
appId : window.fb_app_id, | |
channelUrl : '/channel.php', | |
status : true, | |
cookie : true, | |
xfbml : true | |
}); | |
FB.Canvas.setSize({ width: 810, height: $('body').height() > 800 ? $('body').height() : 800}); | |
var updateScrollInfoCallback = function(info) { | |
window.parent_scroll = info.scrollTop; | |
window.parent_height = info.clientHeight; | |
$('.i-popup').css('top', (window.parent_scroll + 10) + 'px'); | |
} | |
var updateScrollInfo = function () | |
{ | |
FB.Canvas.getPageInfo(updateScrollInfoCallback); | |
} | |
window.setInterval(updateScrollInfo, 500); | |
$('.share').click(function(ev) { | |
ev.preventDefault(); | |
var _this = this; | |
$(_this).html('Загрузка…'); | |
FB.api({ method: 'fql.query', query: 'select aid from album where owner=me() and type="wall"' }, function(res) { | |
if (!res.length) | |
{ | |
if (typeof window.share_on_load == 'undefined') | |
{ | |
alert('Ошибка при публикации фото. Попробуйте опубликовать позднее'); | |
} | |
} | |
var aid = res[0].aid; | |
FB.api('/me/photos', { aid: aid, url: $('.b-photo__item img').attr('src'), name: 'Я участвую в конкурсе «Выиграй с Шараповой», поддержи меня лайком! http://www.facebook.com/SamsungMobileRussia/app_478628068823931' }, 'post', function(res) { | |
if (res.id) | |
{ | |
if (typeof window.share_on_load == 'undefined') | |
{ | |
alert('Фотография опубликована'); | |
} | |
} | |
else | |
{ | |
if (typeof window.share_on_load == 'undefined') | |
{ | |
alert('Ошибка при публикации фото. Попробуйте опубликовать позднее'); | |
} | |
} | |
$(_this).html('Поделиться'); | |
}); | |
}); | |
return false; | |
}); | |
if (typeof window.share_on_load != 'undefined') | |
{ | |
FB.getLoginStatus(function(response){ | |
$('.share').trigger('click'); | |
}); | |
} | |
if (ids.length > 0) | |
{ | |
ids = ids.join(','); | |
FB.api({ method: 'fql.query', query: 'select uid, name, pic_square from user where uid in ('+ids+')', locale: 'ru_RU' }, function(response) { | |
for (var i in response) | |
{ | |
var data = response[i]; | |
$('[data-id=' + data.uid + ']').each(function(i, el) { | |
if ($(el).data('replace') == 'name') | |
{ | |
$(el).html( data.name ); | |
} | |
else if ($(el).data('replace') == 'image') | |
{ | |
$(el).attr('src', data.pic_square); | |
} | |
}); | |
} | |
}); | |
} | |
$('.accept-photo').click(function(ev) { | |
var _this = $(this); | |
FB.api('/me?locale=ru_RU', function(response) { | |
var username = response.name; | |
var form = $('<form method="post" action=""></form>'); | |
form.attr('action', $(_this).attr('href')); | |
var input = $('<input type="hidden" name="username" value="" />'); | |
form.append(input); | |
$('body').append(form); | |
$(input).val(username); | |
form.submit(); | |
}); | |
return false; | |
}); | |
$('.b-photo__tarea .ok').click(function() { | |
var form = $(this).parents('form'); | |
if (form.find('input[name=username]').length == 0) | |
{ | |
form.submit(); | |
return false; | |
} | |
FB.api('/me?locale=ru_RU', function(response) { | |
var username = response.name; | |
form.find('input[name=username]').val(username); | |
form.submit(); | |
}); | |
return false; | |
}); | |
} | |
$formStart.submit(function(e) { | |
AIM.submit(this, { | |
onComplete: function(response) { | |
response = $.parseJSON(response); | |
if (response.status) | |
{ | |
if (!window.location.origin) window.location.origin = window.location.protocol+"//"+window.location.host; | |
window.location.href = window.location.origin + window.url_base + '/main/acceptPhoto?social=' + window.social; | |
} | |
else | |
{ | |
$body.trigger('formError.Samsung', response.error); | |
} | |
} | |
}); | |
}); | |
$formStartOne.find('.file').on('change', function() { | |
$formStart.submit(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment