Merge pull request #1483 from buddha87/master

Fixed #150 #1472: Insert new entries after sticked entries. Reload St…
This commit is contained in:
Lucas Bartholemy 2016-02-17 22:42:03 +01:00
commit a32b201598
5 changed files with 44 additions and 50 deletions

View File

@ -203,8 +203,7 @@ function Stream(baseElement) {
me = this;
$("#wallEntry_" + wallEntryId).each(function () {
me.loadedEntryCount -= 1;
$(this).hide();
$(this).remove();
});
// Start normal stream
@ -219,7 +218,7 @@ function Stream(baseElement) {
*/
this.prependEntry = function (wallEntryId) {
me = this;
var me = this;
// Start normal stream
if (this.currentMode == 'single' || this.loadedEntryCount == 0) {
@ -227,7 +226,7 @@ function Stream(baseElement) {
return;
}
url = streamUrl;
var url = streamUrl;
url = url.replace('-filter-', '');
url = url.replace('-sort-', '');
url = url.replace('-from-', parseInt(wallEntryId)+1);
@ -236,9 +235,18 @@ function Stream(baseElement) {
jQuery.getJSON(url, function (json) {
me.loadedEntryCount += 1;
streamDiv = $(me.baseDiv).find(".s2_streamContent");
$(parseEntriesHtml(json)).prependTo($(streamDiv)).fadeIn('fast');
var $streamDiv = $(me.baseDiv).find(".s2_streamContent");
var $newEntryHtml = $(parseEntriesHtml(json)).hide();
var $firstUnstickedEntry = $streamDiv.find('.wall-entry:not(.sticked-entry)').first();
if($firstUnstickedEntry.length) {
$firstUnstickedEntry.before($newEntryHtml);
$newEntryHtml.fadeIn('fast');
} else {
$newEntryHtml.prependTo($streamDiv).fadeIn('fast');
}
me.onNewEntries();
// In case of first post / hide message
@ -246,7 +254,7 @@ function Stream(baseElement) {
});
}
};
/**

View File

@ -25,11 +25,8 @@ function wallUnstick(url) {
url: url
}).done(function (data) {
if (data.success) {
if (currentStream) {
$.each(data.wallEntryIds, function (k, wallEntryId) {
currentStream.reloadWallEntry(wallEntryId);
});
}
//Reload the whole stream, since we have to reorder the entries
currentStream.showStream();
}
});
}

View File

@ -398,7 +398,8 @@ class Content extends \humhub\components\ActiveRecord
public function stick()
{
$this->sticked = 1;
$this->save();
//This prevents the call of beforesave, and the setting of update_at
$this->updateAttributes(['sticked']);
}
/**
@ -408,7 +409,7 @@ class Content extends \humhub\components\ActiveRecord
{
$this->sticked = 0;
$this->save();
$this->updateAttributes(['sticked']);
}
/**

View File

@ -10,8 +10,11 @@
* @since 0.5
*/
?>
<?php if ($mode != "activity") : ?>
<div class="wall-entry" id="wallEntry_<?php echo $entry->id; ?>">
<?php
$cssClass = ($entry->content->sticked) ? 'wall-entry sticked-entry' : 'wall-entry';
if ($mode != "activity") : ?>
<div class="<?php echo $cssClass ?>" id="wallEntry_<?php echo $entry->id; ?>">
<?php endif; ?>
<?php echo $content; ?>

View File

@ -9,18 +9,14 @@ use yii\helpers\Url;
$(document).ready(function () {
// Get placeholder
var placeholder = $('#<?php echo $id; ?>').attr('placeholder');
// hide original input element
$('#<?php echo $id; ?>').hide();
// check if contenteditable div already exists
if ($('#<?php echo $id; ?>_contenteditable').length == 0) {
// add contenteditable div
$('#<?php echo $id; ?>').after('<div id="<?php echo $id; ?>_contenteditable" class="atwho-input form-control atwho-placeholder" data-query="0" contenteditable="true">' + placeholder + '</div>');
//The original form input element will be hidden
var $formInput = $('#<?php echo $id; ?>').hide();
var placeholder = $formInput.attr('placeholder');
var $editableContent = $('#<?php echo $id; ?>_contenteditable');
if (!$editableContent.length) {
$editableContent = $formInput.after('<div id="<?php echo $id; ?>_contenteditable" class="atwho-input form-control atwho-placeholder" data-query="0" contenteditable="true">' + placeholder + '</div>');
}
var emojis = [
@ -41,7 +37,7 @@ use yii\helpers\Url;
});
// init at plugin
$('#<?php echo $id; ?>_contenteditable').atwho({
$editableContent.atwho({
at: "@",
data: ["<?php echo Yii::t('base', 'Please type at least 3 characters') ?>"],
insert_tpl: "<a href='<?php echo Url::to(['/user/profile']); ?>/&uguid=${guid}' target='_blank' class='atwho-user' data-user-guid='@-${type}${guid}'>${atwho-data-value}</a>",
@ -95,27 +91,26 @@ use yii\helpers\Url;
limit: 100
});
//it seems atwho detatches the original element so we have to do a requery
$editableContent = $('#<?php echo $id; ?>_contenteditable');
// remove placeholder text
$('#<?php echo $id; ?>_contenteditable').focus(function () {
$editableContent.on('focus', function () {
$(this).removeClass('atwho-placeholder');
if ($(this).html() == placeholder) {
$(this).html('');
$(this).focus();
}
})
// add placeholder text, if input is empty
$('#<?php echo $id; ?>_contenteditable').focusout(function () {
}).on('focusout', function () {
// add placeholder text, if input is empty
if ($(this).html() == "" || $(this).html() == " " || $(this).html() == " <br>") {
$(this).html(placeholder);
$(this).addClass('atwho-placeholder');
} else {
$('#<?php echo $id; ?>').val(getPlainInput($(this).clone()));
}
})
$('#<?php echo $id; ?>_contenteditable').on('paste', function (event) {
}).on('paste', function (event) {
// disable standard behavior
@ -138,29 +133,19 @@ use yii\helpers\Url;
// set plain text at current cursor position
insertTextAtCursor($result.text());
});
$('#<?php echo $id; ?>_contenteditable').keypress(function (e) {
}).on('keypress', function (e) {
if (e.which == 13) {
// insert a space by hitting enter for a clean convert of user guids
insertTextAtCursor(' ');
}
});
$('#<?php echo $id; ?>_contenteditable').on("shown.atwho", function (event) {
}).on("shown.atwho", function (event) {
// set attribute for showing search results
$(this).attr('data-query', '1');
});
$('#<?php echo $id; ?>_contenteditable').on("inserted.atwho", function (event, $li) {
}).on("inserted.atwho", function (event, $li) {
// set attribute for showing search hint
$(this).attr('data-query', '0');
});
})
;
});
/**
* Convert contenteditable div content into plain text