[-] MO : productComments - Fixed guest comments
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8286 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
1 parent
44976ee2eb
commit
5195452a3f
3 files changed
+183
-1
No files matched your search
@@ -0,0 +1,163 @@
|
|||||||
|
/*
|
||||||
|
* jQuery Textarea Characters Counter Plugin v 2.0
|
||||||
|
* Examples and documentation at: http://roy-jin.appspot.com/jsp/textareaCounter.jsp
|
||||||
|
* Copyright (c) 2010 Roy Jin
|
||||||
|
* Version: 2.0 (11-JUN-2010)
|
||||||
|
* Dual licensed under the MIT and GPL licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl.html
|
||||||
|
* Requires: jQuery v1.4.2 or later
|
||||||
|
*/
|
||||||
|
(function($){
|
||||||
|
$.fn.textareaCount = function(options, fn) {
|
||||||
|
var defaults = {
|
||||||
|
maxCharacterSize: -1,
|
||||||
|
originalStyle: 'originalTextareaInfo',
|
||||||
|
warningStyle: 'warningTextareaInfo',
|
||||||
|
warningNumber: 20,
|
||||||
|
displayFormat: '#input characters | #words words'
|
||||||
|
};
|
||||||
|
var options = $.extend(defaults, options);
|
||||||
|
|
||||||
|
var container = $(this);
|
||||||
|
|
||||||
|
$("<div class='charleft'> </div>").insertAfter(container);
|
||||||
|
|
||||||
|
//create charleft css
|
||||||
|
var charLeftCss = {
|
||||||
|
'width' : container.width()
|
||||||
|
};
|
||||||
|
|
||||||
|
var charLeftInfo = getNextCharLeftInformation(container);
|
||||||
|
charLeftInfo.addClass(options.originalStyle);
|
||||||
|
charLeftInfo.css(charLeftCss);
|
||||||
|
|
||||||
|
var numInput = 0;
|
||||||
|
var maxCharacters = options.maxCharacterSize;
|
||||||
|
var numLeft = 0;
|
||||||
|
var numWords = 0;
|
||||||
|
|
||||||
|
container.bind('keyup', function(event){limitTextAreaByCharacterCount();})
|
||||||
|
.bind('mouseover', function(event){setTimeout(function(){limitTextAreaByCharacterCount();}, 10);})
|
||||||
|
.bind('paste', function(event){setTimeout(function(){limitTextAreaByCharacterCount();}, 10);});
|
||||||
|
|
||||||
|
|
||||||
|
function limitTextAreaByCharacterCount(){
|
||||||
|
charLeftInfo.html(countByCharacters());
|
||||||
|
//function call back
|
||||||
|
if(typeof fn != 'undefined'){
|
||||||
|
fn.call(this, getInfo());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function countByCharacters(){
|
||||||
|
var content = container.val();
|
||||||
|
var contentLength = content.length;
|
||||||
|
|
||||||
|
//Start Cut
|
||||||
|
if(options.maxCharacterSize > 0){
|
||||||
|
//If copied content is already more than maxCharacterSize, chop it to maxCharacterSize.
|
||||||
|
if(contentLength >= options.maxCharacterSize) {
|
||||||
|
content = content.substring(0, options.maxCharacterSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
var newlineCount = getNewlineCount(content);
|
||||||
|
|
||||||
|
// newlineCount new line character. For windows, it occupies 2 characters
|
||||||
|
var systemmaxCharacterSize = options.maxCharacterSize - newlineCount;
|
||||||
|
if (!isWin()){
|
||||||
|
systemmaxCharacterSize = options.maxCharacterSize
|
||||||
|
}
|
||||||
|
if(contentLength > systemmaxCharacterSize){
|
||||||
|
//avoid scroll bar moving
|
||||||
|
var originalScrollTopPosition = this.scrollTop;
|
||||||
|
container.val(content.substring(0, systemmaxCharacterSize));
|
||||||
|
this.scrollTop = originalScrollTopPosition;
|
||||||
|
}
|
||||||
|
charLeftInfo.removeClass(options.warningStyle);
|
||||||
|
if(systemmaxCharacterSize - contentLength <= options.warningNumber){
|
||||||
|
charLeftInfo.addClass(options.warningStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
numInput = container.val().length + newlineCount;
|
||||||
|
if(!isWin()){
|
||||||
|
numInput = container.val().length;
|
||||||
|
}
|
||||||
|
|
||||||
|
numWords = countWord(getCleanedWordString(container.val()));
|
||||||
|
|
||||||
|
numLeft = maxCharacters - numInput;
|
||||||
|
} else {
|
||||||
|
//normal count, no cut
|
||||||
|
var newlineCount = getNewlineCount(content);
|
||||||
|
numInput = container.val().length + newlineCount;
|
||||||
|
if(!isWin()){
|
||||||
|
numInput = container.val().length;
|
||||||
|
}
|
||||||
|
numWords = countWord(getCleanedWordString(container.val()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatDisplayInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDisplayInfo(){
|
||||||
|
var format = options.displayFormat;
|
||||||
|
format = format.replace('#input', numInput);
|
||||||
|
format = format.replace('#words', numWords);
|
||||||
|
//When maxCharacters <= 0, #max, #left cannot be substituted.
|
||||||
|
if(maxCharacters > 0){
|
||||||
|
format = format.replace('#max', maxCharacters);
|
||||||
|
format = format.replace('#left', numLeft);
|
||||||
|
}
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getInfo(){
|
||||||
|
var info = {
|
||||||
|
input: numInput,
|
||||||
|
max: maxCharacters,
|
||||||
|
left: numLeft,
|
||||||
|
words: numWords
|
||||||
|
};
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNextCharLeftInformation(container){
|
||||||
|
return container.next('.charleft');
|
||||||
|
}
|
||||||
|
|
||||||
|
function isWin(){
|
||||||
|
var strOS = navigator.appVersion;
|
||||||
|
if (strOS.toLowerCase().indexOf('win') != -1){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNewlineCount(content){
|
||||||
|
var newlineCount = 0;
|
||||||
|
for(var i=0; i<content.length;i++){
|
||||||
|
if(content.charAt(i) == '\n'){
|
||||||
|
newlineCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newlineCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCleanedWordString(content){
|
||||||
|
var fullStr = content + " ";
|
||||||
|
var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
|
||||||
|
var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
|
||||||
|
var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
|
||||||
|
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
|
||||||
|
var splitString = cleanedStr.split(" ");
|
||||||
|
return splitString;
|
||||||
|
}
|
||||||
|
|
||||||
|
function countWord(cleanedWordString){
|
||||||
|
var word_count = cleanedWordString.length-1;
|
||||||
|
return word_count;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})(jQuery);
|
||||||
@@ -52,6 +52,7 @@ elseif (Tools::getValue('action') AND Tools::getValue('secure_key') == $productC
|
|||||||
$id_product = 0;
|
$id_product = 0;
|
||||||
$content = null;
|
$content = null;
|
||||||
$title = null;
|
$title = null;
|
||||||
|
$name = null;
|
||||||
$grades = array();
|
$grades = array();
|
||||||
foreach ($review as $entry)
|
foreach ($review as $entry)
|
||||||
{
|
{
|
||||||
@@ -61,6 +62,8 @@ elseif (Tools::getValue('action') AND Tools::getValue('secure_key') == $productC
|
|||||||
$title = $entry->value;
|
$title = $entry->value;
|
||||||
elseif ($entry->key == "content")
|
elseif ($entry->key == "content")
|
||||||
$content = $entry->value;
|
$content = $entry->value;
|
||||||
|
elseif ($entry->key == "customer_name")
|
||||||
|
$name = $entry->value;
|
||||||
elseif (preg_match("/grade/", $entry->key))
|
elseif (preg_match("/grade/", $entry->key))
|
||||||
{
|
{
|
||||||
$id = array(preg_split("/_/", $entry->key));
|
$id = array(preg_split("/_/", $entry->key));
|
||||||
@@ -72,7 +75,8 @@ elseif (Tools::getValue('action') AND Tools::getValue('secure_key') == $productC
|
|||||||
die('0');
|
die('0');
|
||||||
|
|
||||||
$allow_guests = (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS');
|
$allow_guests = (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS');
|
||||||
if (Context::getContext()->customer->id AND (!Context::getContext()->customer->is_guest OR $allow_guests))
|
|
||||||
|
if (Context::getContext()->customer->id OR (!Context::getContext()->customer->id AND $allow_guests))
|
||||||
{
|
{
|
||||||
$id_guest = (!$id_customer = (int)Context::getContext()->cookie->id_customer) ? (int)Context::getContext()->cookie->id_guest : false;
|
$id_guest = (!$id_customer = (int)Context::getContext()->cookie->id_customer) ? (int)Context::getContext()->cookie->id_guest : false;
|
||||||
$customerComment = ProductComment::getByCustomer((int)($id_product), Context::getContext()->cookie->id_customer, true, (int)$id_guest);
|
$customerComment = ProductComment::getByCustomer((int)($id_product), Context::getContext()->cookie->id_customer, true, (int)$id_guest);
|
||||||
@@ -83,6 +87,7 @@ elseif (Tools::getValue('action') AND Tools::getValue('secure_key') == $productC
|
|||||||
$customer_name = false;
|
$customer_name = false;
|
||||||
if ($id_guest AND (!$customer_name = Context::getContext()->customer->firstname . " " . Context::getContext()->customer->lastname))
|
if ($id_guest AND (!$customer_name = Context::getContext()->customer->firstname . " " . Context::getContext()->customer->lastname))
|
||||||
$errors[] = $productCom->l('Please fill your name');
|
$errors[] = $productCom->l('Please fill your name');
|
||||||
|
|
||||||
if (!sizeof($errors) AND $content)
|
if (!sizeof($errors) AND $content)
|
||||||
{
|
{
|
||||||
$comment = new ProductComment();
|
$comment = new ProductComment();
|
||||||
@@ -91,6 +96,8 @@ elseif (Tools::getValue('action') AND Tools::getValue('secure_key') == $productC
|
|||||||
$comment->id_customer = (int)Context::getContext()->cookie->id_customer;
|
$comment->id_customer = (int)Context::getContext()->cookie->id_customer;
|
||||||
$comment->id_guest = (int)$id_guest;
|
$comment->id_guest = (int)$id_guest;
|
||||||
$comment->customer_name = pSQL($customer_name);
|
$comment->customer_name = pSQL($customer_name);
|
||||||
|
if (!$comment->id_customer)
|
||||||
|
$comment->customer_name = pSQL($name);
|
||||||
$comment->title = pSQL($title);
|
$comment->title = pSQL($title);
|
||||||
$comment->grade = 0;
|
$comment->grade = 0;
|
||||||
$comment->validate = 0;
|
$comment->validate = 0;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*}
|
*}
|
||||||
<script type="text/javascript" src="{$module_dir}js/jquery.rating.pack.js"></script>
|
<script type="text/javascript" src="{$module_dir}js/jquery.rating.pack.js"></script>
|
||||||
|
<script type="text/javascript" src="{$module_dir}js/jquery.textareaCounter.plugin.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function(){literal}{{/literal} $('input[@type=radio].star').rating(); {literal}}{/literal});
|
$(function(){literal}{{/literal} $('input[@type=radio].star').rating(); {literal}}{/literal});
|
||||||
$(function(){literal}{{/literal}
|
$(function(){literal}{{/literal}
|
||||||
@@ -40,6 +41,17 @@
|
|||||||
{rdelim}
|
{rdelim}
|
||||||
|
|
||||||
$('document').ready(function(){literal}{{/literal}
|
$('document').ready(function(){literal}{{/literal}
|
||||||
|
|
||||||
|
var limitInputText = {
|
||||||
|
'maxCharacterSize': 200,
|
||||||
|
'originalStyle': 'originalDisplayInfo',
|
||||||
|
'warningStyle': 'warningDisplayInfo',
|
||||||
|
'warningNumber': 40,
|
||||||
|
'displayFormat': '#left'
|
||||||
|
};
|
||||||
|
|
||||||
|
$('#commentContent').textareaCount(limitInputText);
|
||||||
|
|
||||||
$('#new_comment_btn').fancybox({literal}{{/literal}
|
$('#new_comment_btn').fancybox({literal}{{/literal}
|
||||||
'hideOnContentClick': false,
|
'hideOnContentClick': false,
|
||||||
'onClosed': function(){literal}{{/literal}
|
'onClosed': function(){literal}{{/literal}
|
||||||
|
|||||||
Reference in new issue
Block a user