1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-29 04:55:02 +03:00

Рефакторинг jQuery-кода

This commit is contained in:
kirsan 2011-07-20 14:47:20 +00:00
parent 6ab6db1184
commit 5cfacd7dd6
5 changed files with 116 additions and 110 deletions

View file

@ -116,7 +116,7 @@ tinyMCE.init({
<p id="topic-photo-upload-input" class="topic-photo-upload-input">
<label for="">{$aLang.topic_photoset_choose_image}:</label><br />
<input type="file" id="photoset-upload-file" name="Filedata" />
<a href="javascript:photosetUploadPhoto()" >upload</a>
<a href="javascript:ls.photoset.upload()" >upload</a>
<input type="hidden" name="is_iframe" value="true" />
<input type="hidden" name="topic_id" value="{$_aRequest.topic_id}" />
</p>
@ -183,7 +183,7 @@ tinyMCE.init({
<div class="topic-photo-upload-rules">
{$aLang.topic_photoset_upload_rules|ls_lang:"SIZE%%`$oConfig->get('module.topic.photoset.photo_max_size')`":"COUNT%%`$oConfig->get('module.topic.photoset.count_photos_max')`"}
</div>
<a href="javascript:photosetShowUploadForm()">Загрузить фото</a>
<a href="javascript:ls.photoset.showForm()">Загрузить фото</a>
<input type="hidden" name="topic_main_photo" id="topic_main_photo" />
<ul id="swfu_images">
{if count($aPhotos)}
@ -193,13 +193,13 @@ tinyMCE.init({
{/if}
<li id="photo_{$oPhoto->getId()}" {if $bIsMainPhoto}class="marked-as-preview"{/if}>
<img src="{$oPhoto->getWebPath(100)}" alt="image" />
<textarea onBlur="topicImageSetDescription({$oPhoto->getId()}, this.value)">{$oPhoto->getDescription()}</textarea><br />
<a href="javascript:deleteTopicImage({$oPhoto->getId()})" class="image-delete">Удалить</a>
<textarea onBlur="ls.photoset.setPreviewDescription({$oPhoto->getId()}, this.value)">{$oPhoto->getDescription()}</textarea><br />
<a href="javascript:ls.photoset.deletePhoto({$oPhoto->getId()})" class="image-delete">Удалить</a>
<span class="photo-preview-state">
{if $bIsMainPhoto}
{$aLang.topic_photoset_is_preview}
{else}
<a href="javascript:setTopicMainPhoto({$oPhoto->getId()})" class="mark-as-preview">{$aLang.topic_photoset_mark_as_preview}</a>
<a href="javascript:ls.photoset.setPreview({$oPhoto->getId()})" class="mark-as-preview">{$aLang.topic_photoset_mark_as_preview}</a>
{/if}
</span>
</li>

View file

@ -1,103 +0,0 @@
function addTopicImage(response)
{
if (!response.bStateError) {
template = '<li id="photo_'+response.id+'"><a href="#"><img src="'+response.file+'" alt="image" /></a>'
+'<textarea onBlur="topicImageSetDescription('+response.id+', this.value)"></textarea><br />'
+'<a href="javascript:deleteTopicImage('+response.id+')" class="image-delete">'+lsLang['delete']+'</a>'
+'<span class="photo-preview-state"><a href="javascript:setTopicMainPhoto('+response.id+')" class="mark-as-preview">'+lsLang['mark_as_preview']+'</a></span></li>';
$('#swfu_images').append(template);
ls.msg.notice(response.sMsgTitle,response.sMsg);
} else {
ls.msg.error(response.sMsgTitle,response.sMsg);
}
photosetCloseForm();
}
function deleteTopicImage(id)
{
ls.ajax(aRouter['photoset']+'deleteimage', {'id':id, 'security_ls_key': LIVESTREET_SECURITY_KEY }, function(response){
if (!response.bStateError) {
$('#photo_'+id).remove();
ls.msg.notice(response.sMsgTitle,response.sMsg);
} else {
ls.msg.error('Error','Please try again later');
}
});
}
function setTopicMainPhoto(id)
{
$('#topic_main_photo').val(id);
$('.marked-as-preview').each(function (index, el) {
$(el).removeClass('marked-as-preview');
$(el).children('span').html('<a href="javascript:setTopicMainPhoto('+$(el).attr('id').slice($(el).attr('id').lastIndexOf('_')+1)+')" class="mark-as-preview">'+lsLang['mark_as_preview']+'</a>');
});
$('#photo_'+id).addClass('marked-as-preview');
$('#photo_'+id).children('span').html(lsLang['preview']);
}
function topicImageSetDescription(id, text)
{
ls.ajax(aRouter['photoset']+'setimagedescription', {'id':id, 'text':text, 'security_ls_key': LIVESTREET_SECURITY_KEY }, function(result){
if (!bStateError) {
} else {
msgErrorBox.alert('Error','Please try again later');
}
}
)
}
function getMorePhotos(topic_id)
{
var last_id = $('#last_photo_id').val();
ls.ajax(aRouter['photoset']+'getmore', {'topic_id':topic_id, 'last_id':last_id, 'security_ls_key': LIVESTREET_SECURITY_KEY }, function(result){
if (!result.bStateError) {
if (result.photos) {
var photoNumber = $('#photo_number').val();
$.each(result.photos, function(index, photo) {
var image = '<li><div class="image-number">'+(photoNumber++)+'</div><a class="photoset-image" href="'+photo.path+'" rel="[photoset]" title="'+photo.description+'"><img src="'+photo.path_thumb+'" alt="'+photo.description+'" /></a></li>';
$('#topic-photo-images').append(image);
$('#photo_number').val(photoNumber);
$('#last_photo_id').val(photo.id);
$('.photoset-image').unbind('click');
$('.photoset-image').prettyPhoto({
social_tools:'',
show_title: false,
slideshow:false,
deeplinking: false
});
});
} else {
$('#topic-photo-more').remove();
}
} else {
msgErrorBox.alert('Error','Please try again later');
}
});
}
function photosetUploadPhoto()
{
ls.ajaxSubmit(aRouter['photoset']+'upload/',$('#photoset-upload-form'),function(data){
if (data.bStateError) {
ls.msg.error(data.sMsgTitle,data.sMsg);
} else {
addTopicImage(data);
}
});
photosetCloseForm();
}
function photosetCloseForm() {
$('#photoset-upload-form').css('left', '-300px');
}
function photosetShowUploadForm()
{
if ($('#photoset-upload-file').length) {
$('#photoset-upload-file').val( '');
}
$('#photoset-upload-form').css('left', '50%');
}

View file

@ -0,0 +1,109 @@
var ls = ls || {};
ls.photoset =( function ($) {
this.addPhoto = function(response)
{
if (!response.bStateError) {
template = '<li id="photo_'+response.id+'"><a href="#"><img src="'+response.file+'" alt="image" /></a>'
+'<textarea onBlur="ls.photoset.setPreviewDescription('+response.id+', this.value)"></textarea><br />'
+'<a href="javascript:ls.photoset.deletePhoto('+response.id+')" class="image-delete">'+lsLang['delete']+'</a>'
+'<span class="photo-preview-state"><a href="javascript:ls.photoset.setPreview('+response.id+')" class="mark-as-preview">'+lsLang['mark_as_preview']+'</a></span></li>';
$('#swfu_images').append(template);
ls.msg.notice(response.sMsgTitle,response.sMsg);
} else {
ls.msg.error(response.sMsgTitle,response.sMsg);
}
photosetCloseForm();
}
this.deletePhoto = function(id)
{
ls.ajax(aRouter['photoset']+'deleteimage', {'id':id}, function(response){
if (!response.bStateError) {
$('#photo_'+id).remove();
ls.msg.notice(response.sMsgTitle,response.sMsg);
} else {
ls.msg.error('Error','Please try again later');
}
});
}
this.setPreview =function(id)
{
$('#topic_main_photo').val(id);
$('.marked-as-preview').each(function (index, el) {
$(el).removeClass('marked-as-preview');
$(el).children('span').html('<a href="javascript:ls.photoset.setDescription('+$(el).attr('id').slice($(el).attr('id').lastIndexOf('_')+1)+')" class="mark-as-preview">'+lsLang['mark_as_preview']+'</a>');
});
$('#photo_'+id).addClass('marked-as-preview');
$('#photo_'+id).children('span').html(lsLang['preview']);
}
this.setPreviewDescription = function(id, text)
{
ls.ajax(aRouter['photoset']+'setimagedescription', {'id':id, 'text':text}, function(result){
if (!bStateError) {
} else {
ls.msg.error('Error','Please try again later');
}
}
)
}
this. getMore = function(topic_id)
{
var last_id = $('#last_photo_id').val();
ls.ajax(aRouter['photoset']+'getmore', {'topic_id':topic_id, 'last_id':last_id}, function(result){
if (!result.bStateError) {
if (result.photos) {
var photoNumber = $('#photo_number').val();
$.each(result.photos, function(index, photo) {
var image = '<li><div class="image-number">'+(photoNumber++)+'</div><a class="photoset-image" href="'+photo.path+'" rel="[photoset]" title="'+photo.description+'"><img src="'+photo.path_thumb+'" alt="'+photo.description+'" /></a></li>';
$('#topic-photo-images').append(image);
$('#photo_number').val(photoNumber);
$('#last_photo_id').val(photo.id);
$('.photoset-image').unbind('click');
$('.photoset-image').prettyPhoto({
social_tools:'',
show_title: false,
slideshow:false,
deeplinking: false
});
});
} else {
$('#topic-photo-more').remove();
}
} else {
ls.msg.error('Error','Please try again later');
}
});
}
this.upload = function()
{
ls.ajaxSubmit(aRouter['photoset']+'upload/',$('#photoset-upload-form'),function(data){
if (data.bStateError) {
ls.msg.error(data.sMsgTitle,data.sMsg);
} else {
ls.photoset.addPhoto(data);
}
});
ls.photoset.closeForm();
}
this.closeForm = function()
{
$('#photoset-upload-form').css('left', '-300px');
}
this.showForm = function()
{
if ($('#photoset-upload-file').length) {
$('#photoset-upload-file').val( '');
}
$('#photoset-upload-form').css('left', '50%');
}
return this;
}).call(ls.photoset || {},jQuery);

View file

@ -25,7 +25,7 @@ $config['head']['default']['js'] = array(
"___path.static.skin___/js/friend.js",
"___path.static.skin___/js/userfeed.js",
"___path.static.skin___/js/stream.js",
"___path.static.skin___/js/other.js",
"___path.static.skin___/js/photoset.js",
);
$config['head']['default']['css'] = array(
"___path.static.skin___/css/reset.css",

View file

@ -80,7 +80,7 @@
</ul>
<input type="hidden" id="photo_number" value="{$iPhotoNumber}" />
<input type="hidden" id="last_photo_id" value="{$iLastPhotoId}" />
<a href="javascript:getMorePhotos({$oTopic->getId()})" id="topic-photo-more" class="topic-photo-more">{$aLang.topic_photoset_show_more} &darr;</a>
<a href="javascript:ls.photoset.getMore({$oTopic->getId()})" id="topic-photo-more" class="topic-photo-more">{$aLang.topic_photoset_show_more} &darr;</a>
</div>
{/if}
<!-- /Topic Photo Image List -->