[+] MO : Added HomeSlider

This commit is contained in:
bMancone
2011-08-24 12:45:50 +00:00
parent 13480f5fef
commit 4184ec3eb9
13 changed files with 1163 additions and 0 deletions
+160
View File
@@ -0,0 +1,160 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HomeSlide extends ObjectModel
{
public $title;
public $description;
public $url;
public $legend;
public $image;
public $active;
public $position;
public $maxImageSize = 307200;
protected $fieldsValidate = array(
'active' => 'isunsignedInt',
'position' => 'isunsignedInt'
);
protected $fieldsRequired = array(
'active',
'position'
);
protected $fieldsRequiredLang = array('title', 'description', 'url', 'legend');
protected $fieldsSizeLang = array(
'description' => 4000,
'title' => 255,
'legend' => 255,
'url' => 255,
'image' => 255
);
protected $fieldsValidateLang = array(
'title' => 'isName',
'description' => 'isCleanHtml',
'url' => 'isUrl',
'legend' => 'isCleanHtml',
'image' => 'isCleanHtml'
);
protected $tables = array('homeslider_slides, homeslider_slides_lang');
protected $table = 'homeslider_slides';
protected $identifier = 'id_slide';
public function getFields()
{
$this->validateFields();
$fields['id_slide'] = (int)$this->id;
$fields['active'] = (int)$this->active;
$fields['position'] = (int)$this->position;
return $fields;
}
public function getTranslationsFieldsChild()
{
$this->validateFieldsLang();
return $this->getTranslationsFields(array(
'title',
'description',
'url',
'legend',
'image'
));
}
public function __construct($id_slide = NULL, $id_lang = NULL, $id_shop = NULL, Context $context = NULL)
{
parent::__construct($id_slide, $id_lang, $id_shop);
}
public function add()
{
$context = Context::getContext();
$id_shop = $context->shop->getID();
$res = parent::add();
$res &= Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'homeslider` (`id_shop`, `id_slide`)
VALUES('.(int)$id_shop.', '.(int)$this->id.')'
);
return $res;
}
public function delete()
{
$res = null;
$images = $this->image;
foreach ($images as $image)
{
if (file_exists(dirname(__FILE__).'/images/'.$image))
$res &= @unlink(dirname(__FILE__).'/images/'.$image);
}
$res &= $this->reOrderPositions();
$res &= Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'homeslider`
WHERE `id_slide` = '.(int)$this->id
);
$res &= parent::delete();
return $res;
}
public function reOrderPositions()
{
$id_slide = $this->id;
$context = Context::getContext();
$id_shop = $context->shop->getID();
$max = Db::getInstance()->ExecuteS('
SELECT MAX(hss.`position`) as position
FROM `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider` hs
WHERE hss.`id_slide` = hs.`id_slide` AND hs.`id_shop` = '.(int)$id_shop
);
if ((int)$max == (int)$id_slide)
return true;
$rows = Db::getInstance()->ExecuteS('
SELECT hss.`position` as position, hss.`id_slide` as id_slide
FROM `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider` hs
WHERE hss.`id_slide` = hs.`id_slide` AND hs.`id_shop` = '.(int)$id_shop.' AND hss.`position` > '.(int)$this->position
);
if (!$rows)
return false;
foreach ($rows as $row)
{
$current_slide = new HomeSlide($row['id_slide']);
--$current_slide->position;
$current_slide->update();
unset($current_slide);
}
return true;
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
include_once('../../config/config.inc.php');
include_once('../../init.php');
include_once('homeslider.php');
$context = Context::getContext();
$homeSlider = new HomeSlider();
$slides = array();
if (!Tools::isSubmit('secure_key') OR Tools::getValue('secure_key') != $homeSlider->secure_key OR !Tools::getValue('action'))
die(1);
if (Tools::getValue('action') == 'updateSlidesPosition' && Tools::getValue('slides'))
{
$slides = Tools::getValue('slides');
foreach ($slides as $position => $id_slide)
{
$res = Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'homeslider_slides` SET `position` = '.(int)($position).'
WHERE `id_slide` = '.(int)($id_slide)
);
}
}
+107
View File
@@ -0,0 +1,107 @@
/* @override http://localhost/bxslider_v3_plugin/css/styles.css */
/*
* To change the color scheme of slider change each
* background property for each of the five styles below
*/
/*next button*/
.bx-next {
position:absolute;
top:40%;
right:-50px;
z-index:999;
width: 30px;
height: 30px;
text-indent: -999999px;
background: url(gray_next.png) no-repeat 0 -30px;
}
/*previous button*/
.bx-prev {
position:absolute;
top:40%;
left:-50px;
z-index:999;
width: 30px;
height: 30px;
text-indent: -999999px;
background: url(gray_prev.png) no-repeat 0 -30px;
}
/*pager links*/
.bx-pager a {
margin-right: 5px;
color: #fff;
padding: 3px 8px 3px 6px;
font-size: 12px;
zoom:1;
background: url(gray_pager.png) no-repeat 0 -20px;
}
/*auto start button*/
.bx-auto .start {
background: url(gray_auto.png) no-repeat 0 2px;
padding-left: 13px;
}
/*auto stop button*/
.bx-auto .stop {
background: url(gray_auto.png) no-repeat 0 -14px;
padding-left: 13px;
}
/*
* End color scheme styles
*/
/*next/prev button hover state*/
.bx-next:hover,
.bx-prev:hover {
background-position: 0 0;
}
/*pager links hover and active states*/
.bx-pager .pager-active,
.bx-pager a:hover {
background-position: 0 0;
}
/*pager wrapper*/
.bx-pager {
text-align:center;
padding-top: 7px;
font-size:12px;
color:#666;
}
/*captions*/
.bx-captions {
text-align:center;
font-size: 12px;
padding: 7px 0;
color: #666;
}
/*auto controls*/
.bx-auto {
text-align: center;
padding-top: 15px;
}
.bx-auto a {
color: #666;
font-size: 12px;
}
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>homeslider</name>
<displayName><![CDATA[Image slider for your homepage]]></displayName>
<version><![CDATA[1.0]]></version>
<description><![CDATA[Adds an image slider to your homepage.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[front_office_features]]></tab>
<is_configurable>1</is_configurable>
<need_instance>0</need_instance>
<limited_countries></limited_countries>
</module>
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 869 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 422 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 845 B

+653
View File
@@ -0,0 +1,653 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_'))
exit;
include_once(_PS_MODULE_DIR_.'homeslider/HomeSlide.php');
class HomeSlider extends Module
{
private $_html = '';
public function __construct()
{
$this->name = 'homeslider';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'PrestaShop';
$this->need_instance = 0;
$this->secure_key = Tools::encrypt($this->name);
parent::__construct();
$this->displayName = $this->l('Image slider for your homepage');
$this->description = $this->l('Adds an image slider to your homepage.');
}
public function install()
{
/* Adds Module */
if (parent::install() && $this->registerHook('home') && $this->registerHook('backOfficeTop') && $this->registerHook('header'))
{
/* Sets up configuration */
$res = Configuration::updateValue('HOMESLIDER_WIDTH', '550');
$res &= Configuration::updateValue('HOMESLIDER_HEIGHT', '300');
$res &= Configuration::updateValue('HOMESLIDER_SPEED', '1300');
$res &= Configuration::updateValue('HOMESLIDER_PAUSE', '7700');
/* Creates tables */
return ($res AND $this->createTables());
}
return false;
}
public function uninstall()
{
/* Deletes Module */
if (parent::uninstall() && $this->unregisterHook('home') && $this->unregisterHook('backOfficeTop') && $this->unregisterHook('header'))
{
/* Deletes tables */
$res = $this->deleteTables();
/* Unsets configuration */
$res &= Configuration::deleteByName('HOMESLIDER_WIDTH');
$res &= Configuration::deleteByName('HOMESLIDER_HEIGHT');
$res &= Configuration::deleteByName('HOMESLIDER_SPEED');
$res &= Configuration::deleteByName('HOMESLIDER_PAUSE');
return $res;
}
return false;
}
protected function createTables()
{
/* Slides */
$res = Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'homeslider` (
`id_slide` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_shop` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_slide`, `id_shop`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
');
/* Slides configuration */
$res &= Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'homeslider_slides` (
`id_slide` int(10) unsigned NOT NULL AUTO_INCREMENT,
`position` int(10) unsigned NOT NULL DEFAULT \'0\',
`active` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
PRIMARY KEY (`id_slide`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
');
/* Slides lang configuration */
$res &= Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'homeslider_slides_lang` (
`id_slide` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL,
`title` varchar(255) NOT NULL,
`description` text NOT NULL,
`legend` varchar(255) NOT NULL,
`url` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL,
PRIMARY KEY (`id_slide`,`id_lang`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
');
return $res;
}
protected function deleteTables()
{
$slides = $this->getSlides();
foreach ($slides as $slide)
{
$toDel = new HomeSlide($slide['id_slide']);
$toDel->delete();
}
return Db::getInstance()->Execute('
DROP TABLE `'._DB_PREFIX_.'homeslider`, `'._DB_PREFIX_.'homeslider_slides`, `'._DB_PREFIX_.'homeslider_slides_lang`;
');
}
public function getContent()
{
$this->_html .= '<h2>'.$this->displayName.'.</h2>';
/* Validate & process */
if (Tools::isSubmit('submitSlide') OR Tools::isSubmit('delete_id_slide') OR Tools::isSubmit('submitSlider')
OR Tools::isSubmit('changeStatus'))
{
if ($this->_postValidation())
$this->_postProcess();
$this->_displayForm();
}
elseif (Tools::isSubmit('addSlide') OR (Tools::isSubmit('id_slide') AND $this->slideExists((int)Tools::getValue('id_slide'))))
$this->_displayAddForm();
else
$this->_displayForm();
return $this->_html;
}
private function _displayForm()
{
/* Gets Slides */
$slides = $this->getSlides();
/* Begin fieldset slider */
$this->_html .= '
<fieldset>
<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('Slider configuration').'</legend>';
/* Begin form */
$this->_html .= '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">';
/* Height field */
$this->_html .= '
<label>'.$this->l('Height').':</label>
<div class="margin-form">
<input type="text" name="HOMESLIDER_HEIGHT" id="speed" size="3" value="'.Configuration::get('HOMESLIDER_HEIGHT').'" /> px
</div>';
/* Width field */
$this->_html .= '
<label>'.$this->l('Width').':</label>
<div class="margin-form">
<input type="text" name="HOMESLIDER_WIDTH" id="pause" size="3" value="'.Configuration::get('HOMESLIDER_WIDTH').'" /> px
</div>';
/* Speed field */
$this->_html .= '
<label>'.$this->l('Speed').':</label>
<div class="margin-form">
<input type="text" name="HOMESLIDER_SPEED" id="speed" size="3" value="'.Configuration::get('HOMESLIDER_SPEED').'" /> ms
</div>';
/* Pause field */
$this->_html .= '
<label>'.$this->l('Pause').':</label>
<div class="margin-form">
<input type="text" name="HOMESLIDER_PAUSE" id="pause" size="3" value="'.Configuration::get('HOMESLIDER_PAUSE').'" /> ms
</div>';
/* Save */
$this->_html .= '
<div class="margin-form">
<input type="submit" class="button" name="submitSlider" value="'.$this->l('Save').'" />
</div>';
/* End form */
$this->_html .= '</form>';
/* End fieldset slider */
$this->_html .= '</fieldset>';
$this->_html .= '<br /><br />';
/* Begin fieldset slides */
$this->_html .= '
<fieldset>
<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('Slides configuration').'</legend>
<strong>
<a href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&addSlide">
<img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('Add Slide').'
</a>
</strong>';
/* Display notice if there are no slides yet */
if (!$slides)
$this->_html .= '<p style="margin-left: 40px;">'.$this->l("You did not add any slides yet").'.</p>';
else /* Display slides */
{
$this->_html .= '
<div id="slidesContent" style="width: 400px; margin-top: 30px;">
<ul id="slides">';
foreach ($slides as $slide)
{
$this->_html .= '
<li id="slides_'.$slide['id_slide'].'">
<strong>#'.$slide['id_slide'].'</strong> '.$slide['title'].'
<p style="float: right">'.
$this->displayStatus($slide['id_slide'], $slide['active']).'
<a href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&id_slide='.(int)($slide['id_slide']).'" title="'.$this->l('Edit').'"><img src="'._PS_ADMIN_IMG_.'edit.gif" alt="" /></a>
<a href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&delete_id_slide='.(int)($slide['id_slide']).'" title="'.$this->l('Delete').'"><img src="'._PS_ADMIN_IMG_.'delete.gif" alt="" /></a>
</p>
</li>';
}
$this->_html .= '</ul></div>';
}
// End fieldset
$this->_html .= '</fieldset>';
}
private function _displayAddForm()
{
/* Sets Slide : depends if edited or added */
$slide = null;
if (Tools::isSubmit('id_slide') && $this->slideExists((int)Tools::getValue('id_slide')))
$slide = new HomeSlide((int)Tools::getValue('id_slide'));
/* Checks if directory is writable */
if(!is_writable('.'))
$this->displayWarning($this->l('modules/'.$this->name.' must be writable (CHMOD 755 / 777)'));
/* Gets languages and sets which div requires translations */
$defaultLanguage = (int)Configuration::get('PS_LANG_DEFAULT');
$languages = Language::getLanguages(false);
$divLangName = 'image¤title¤url¤legend¤description';
$this->_html = '<script type="text/javascript">id_language = Number('.$defaultLanguage.');</script>';
/* Form */
$this->_html .= '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST" enctype="multipart/form-data">';
/* Fieldset Upload */
$this->_html .= '
<fieldset class="width3">
<br />
<legend><img src="'._PS_ADMIN_IMG_.'add.gif" alt="" />1 - '.$this->l('Upload your slide').'</legend>';
/* Image */
$this->_html .= '<label>'.$this->l('Select a file').':</label><div class="margin-form">';
foreach ($languages as $language)
{
$this->_html .= '<div id="image_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').';float: left;">';
$this->_html .= '<input type="file" name="image_'.$language['id_lang'].'" id="image_'.$language['id_lang'].'" size="30" value="'.(isset($slide->image[$language['id_lang']]) ? $slide->image[$language['id_lang']] : '').'"/>';
/* Sets image as hidden in case it does not change */
if ($slide && $slide->image[$language['id_lang']])
$this->_html .= '<input type="hidden" name="image_old_'.$language['id_lang'].'" value="'.($slide->image[$language['id_lang']]).'" id="image_old_'.$language['id_lang'].'" />';
/* Display image */
if ($slide && $slide->image[$language['id_lang']])
$this->_html .= '<img src="'.__PS_BASE_URI__.'modules/'.$this->name.'/images/'.$slide->image[$language['id_lang']].'" width="'.(Configuration::get('HOMESLIDER_WIDTH')/2).'" height="'.(Configuration::get('HOMESLIDER_HEIGHT')/2).'" alt=""/>';
$this->_html .= '</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'image', true);
/* End Fieldset Upload */
$this->_html .= '</fieldset><br /><br />';
/* Fieldset edit/add */
$this->_html .= '<fieldset class="width3">';
if (Tools::isSubmit('addSlide')) /* Configure legend */
$this->_html .= '<legend><img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> 2 - '.$this->l('Configure your slide').'</legend>';
else if (Tools::isSubmit('id_slide')) /* Edit legend */
$this->_html .= '<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> 2 - '.$this->l('Edit your slide').'</legend>';
/* Sets id slide as hidden */
if ($slide && Tools::getValue('id_slide'))
$this->_html .= '<input type="hidden" name="id_slide" value="'.$slide->id.'" id="id_slide" />';
/* Sets position as hidden */
$this->_html .= '<input type="hidden" name="position" value="'.(($slide != null) ? ($slide->position) : ($this->getNextPosition())).'" id="position" />';
/* Form content */
/* Title */
$this->_html .= '<br /><label>'.$this->l('Title:').'</label><div class="margin-form">';
foreach ($languages as $language)
{
$this->_html .= '
<div id="title_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').';float: left;">
<input type="text" name="title_'.$language['id_lang'].'" id="title_'.$language['id_lang'].'" size="30" value="'.(isset($slide->title[$language['id_lang']]) ? $slide->title[$language['id_lang']] : '').'"/>
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'title', true);
$this->_html .= '</div><br /><br />';
/* URL */
$this->_html .= '<label>'.$this->l('URL:').'</label><div class="margin-form">';
foreach ($languages as $language)
{
$this->_html .= '
<div id="url_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').';float: left;">
<input type="text" name="url_'.$language['id_lang'].'" id="url_'.$language['id_lang'].'" size="30" value="'.(isset($slide->url[$language['id_lang']]) ? $slide->url[$language['id_lang']] : '').'"/>
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'url', true);
$this->_html .= '</div><br /><br />';
/* Legend */
$this->_html .= '<label>'.$this->l('Legend:').'</label><div class="margin-form">';
foreach ($languages as $language)
{
$this->_html .= '
<div id="legend_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').';float: left;">
<input type="text" name="legend_'.$language['id_lang'].'" id="legend_'.$language['id_lang'].'" size="30" value="'.(isset($slide->legend[$language['id_lang']]) ? $slide->legend[$language['id_lang']] : '').'"/>
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'legend', true);
$this->_html .= '</div><br /><br />';
/* Description */
$this->_html .= '
<label>'.$this->l('Description:').'</label>
<div class="margin-form">';
foreach ($languages as $language)
{
$this->_html .= '<div id="description_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').';float: left;">
<textarea name="description_'.$language['id_lang'].'" rows="10" cols="29">'.(isset($slide->description[$language['id_lang']]) ? $slide->description[$language['id_lang']] : '').'</textarea>
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'description', true);
$this->_html .= '</div><div class="clear"></div><br />';
/* Active */
$this->_html .= '
<label for="active_on">'.$this->l('Active:').'</label>
<div class="margin-form">
<img src="../img/admin/enabled.gif" alt="Yes" title="Yes" />
<input type="radio" name="active_slide" id="active_on" '.(($slide AND (isset($slide->active) AND (int)$slide->active == 0)) ? '' : 'checked="checked" ').' value="1" />
<label class="t" for="active_on">'.$this->l('Yes').'</label>
<img src="../img/admin/disabled.gif" alt="No" title="No" style="margin-left: 10px;" />
<input type="radio" name="active_slide" id="active_off" '.(($slide AND (isset($slide->active) AND (int)$slide->active == 0)) ? 'checked="checked" ' : '').' value="0" />
</div>';
/* Save */
$this->_html .= '
<p class="center">
<input type="submit" class="button" name="submitSlide" value="'.$this->l('Save').'" />
<a class="button" style="position:relative; padding:3px 3px 4px 3px; top:1px" href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'">'.$this->l('Cancel').'</a>
</p>';
/* End of fieldset & form */
$this->_html .= '
</fieldset>
</form>';
}
private function _postValidation()
{
$errors = array();
/* Validation for Slider configuration */
if (Tools::isSubmit('submitSlider'))
{
if (!Validate::isInt(Tools::getValue('HOMESLIDER_SPEED')) OR !Validate::isInt(Tools::getValue('HOMESLIDER_PAUSE')) OR
!Validate::isInt(Tools::getValue('HOMESLIDER_WIDTH')) OR !Validate::isInt(Tools::getValue('HOMESLIDER_HEIGHT')))
$errors[] = $this->l('Invalid values');
} /* Validation for status */
elseif (Tools::isSubmit('changeStatus'))
{
if (!Validate::isInt(Tools::getValue('id_slide')))
$errors[] = $this->l('Invalid slide');
}
/* Validation for Slide */
elseif (Tools::isSubmit('submitSlide'))
{
/* Checks state (active) */
if (!Validate::isInt(Tools::getValue('active_slide')) OR (Tools::getValue('active_slide') != 0 AND Tools::getValue('active_slide') != 1))
$errors[] = $this->l('Invalid slide state');
/* Checks position */
if (!Validate::isInt(Tools::getValue('position')) OR (Tools::getValue('position') < 0))
$errors[] = $this->l('Invalid slide position');
/* If edit : checks id_slide */
if (Tools::isSubmit('id_slide'))
{
if (!Validate::isInt(Tools::getValue('id_slide')) AND !$this->slideExists(Tools::getValue('id_slide')))
$errors[] = $this->l('Invalid id_slide');
}
/* Checks title/url/legend/description/image */
$languages = Language::getLanguages(false);
foreach ($languages as $language)
{
if (strlen(Tools::getValue('title_'.$language['id_lang'])) > 40)
$errors[] = $this->l('Title is too long');
if (strlen(Tools::getValue('legend_'.$language['id_lang'])) > 40)
$errors[] = $this->l('Legend is too long');
if (strlen(Tools::getValue('url_'.$language['id_lang'])) > 40)
$errors[] = $this->l('URL is too long');
if (strlen(Tools::getValue('description_'.$language['id_lang'])) > 200)
$errors[] = $this->l('Description is too long');
if (strlen(Tools::getValue('url_'.$language['id_lang'])) > 0 && !Validate::isUrl(Tools::getValue('url_'.$language['id_lang'])))
$errors[] = $this->l('URL format is not correct');
if (Tools::getValue('image_'.$language['id_lang']) != NULL AND !Validate::isFileName(Tools::getValue('image_'.$language['id_lang'])))
$errors[] = $this->l("Invalid filename");
if (Tools::getValue('image_old_'.$language['id_lang']) != NULL AND !Validate::isFileName(Tools::getValue('image_old_'.$language['id_lang'])))
$errors[] = $this->l("Invalid filename");
}
/* Checks title/url/legend/description for default lang */
$defaultLanguage = (int)Configuration::get('PS_LANG_DEFAULT');
if (strlen(Tools::getValue('title_'.$defaultLanguage)) == 0)
$errors[] = $this->l('Title is not set');
if (strlen(Tools::getValue('legend_'.$defaultLanguage)) == 0)
$errors[] = $this->l('Legend is not set');
if (strlen(Tools::getValue('url_'.$defaultLanguage)) == 0)
$errors[] = $this->l('URL is not set');
if (strlen(Tools::getValue('description_'.$defaultLanguage)) == 0)
$errors[] = $this->l('Description is not set');
if (Tools::getValue('image_'.$defaultLanguage) == "" AND !Validate::isFileName(Tools::getValue('image_'.$defaultLanguage)) AND !Tools::getValue('image_old_'.defaultLanguage))
$errors[] = $this->l("Image is not set");
if (Tools::getValue('image_old_'.$defaultLanguage) AND !Validate::isFileName(Tools::getValue('image_old_'.$defaultLanguage)))
$errors[] = $this->l("Image is not set");
} /* Validation for deletion */
elseif (Tools::isSubmit('delete_id_slide') AND (!Validate::isInt(Tools::getValue('delete_id_slide')) OR !$this->slideExists((int)Tools::getValue('delete_id_slide'))))
$errors[] = $this->l('Invalid id_slide');
/* Display errors if needed */
if (sizeof($errors))
{
$this->_html .= $this->displayError(implode('<br />', $errors));
return false;
}
/* Returns if validation is ok */
return true;
}
private function _postProcess()
{
$errors = array();
/* Processes Slider */
if (Tools::isSubmit('submitSlider'))
{
$res = Configuration::updateValue('HOMESLIDER_WIDTH', (int)Tools::getValue('HOMESLIDER_WIDTH'));
$res &= Configuration::updateValue('HOMESLIDER_HEIGHT', (int)Tools::getValue('HOMESLIDER_HEIGHT'));
$res &= Configuration::updateValue('HOMESLIDER_SPEED', (int)Tools::getValue('HOMESLIDER_SPEED'));
$res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int)Tools::getValue('HOMESLIDER_PAUSE'));
if (!$res)
$errors .= $this->displayError($this->l('Configuration could not be updated'));
$this->_html = $this->displayConfirmation($this->l('Configuration updated'));
} /* Process Slide status */
elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_slide'))
{
$slide = new HomeSlide((int)Tools::getValue('id_slide'));
$slide->active = (int)($slide->active == 0 ? 1 : 0);
$res = $slide->update();
$this->_html = ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayErro($this->l('Configuration could not be updated')));
}
/* Processes Slide */
elseif (Tools::isSubmit('submitSlide'))
{
/* Sets ID if needed */
if (Tools::getValue('id_slide'))
{
$slide = new HomeSlide((int)Tools::getValue('id_slide'));
if (!Validate::isLoadedObject($slide))
{
$this->_html = $this->displayError($this->l('Invalid id_slide'));
return;
}
}
else
$slide = new HomeSlide();
/* Sets position */
$slide->position = (int)Tools::getValue('position');
/* Sets active */
$slide->active = (int)Tools::getValue('active_slide');
/* Sets each langue fields */
$languages = Language::getLanguages(false);
foreach ($languages as $language)
{
if (Tools::getValue('title_'.$language['id_lang']) != "")
$slide->title[$language['id_lang']] = pSQL(Tools::getValue('title_'.$language['id_lang']));
if (Tools::getValue('url_'.$language['id_lang']) != "")
$slide->url[$language['id_lang']] = pSQL(Tools::getValue('url_'.$language['id_lang']));
if (Tools::getValue('legend_'.$language['id_lang']) != "")
$slide->legend[$language['id_lang']] = pSQL(Tools::getValue('legend_'.$language['id_lang']));
if (Tools::getValue('description_'.$language['id_lang']) != "")
$slide->description[$language['id_lang']] = pSQL(Tools::getValue('description_'.$language['id_lang']));
/* Uploads image and sets slide */
if (isset($_FILES['image_'.$language['id_lang']]) AND isset($_FILES['image_'.$language['id_lang']]['tmp_name']) AND !empty($_FILES['image_'.$language['id_lang']]['tmp_name']))
{
if ($error = checkImage($_FILES['image_'.$language['id_lang']], $slide->maxImageSize))
$errors .= $error;
elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES['image_'.$language['id_lang']]['tmp_name'], $tmpName))
return false;
elseif (!imageResize($tmpName, dirname(__FILE__).'/images/'.Tools::encrypt($_FILES['image_'.$language['id_lang']]['name']).'.jpg'))
$errors .= $this->displayError($this->l('An error occurred during the image upload.'));
if (isset($tmpName))
unlink($tmpName);
$slide->image[$language['id_lang']] = pSQL(Tools::encrypt($_FILES['image_'.($language['id_lang'])]['name']).'.jpg');
}
if (Tools::getValue('image_old_'.$language['id_lang']) != "")
$slide->image[$language['id_lang']] = pSQL(Tools::getValue('image_old_'.$language['id_lang']));
}
/* Adds */
if (!Tools::getValue('id_slide'))
{
if (!$slide->add())
$errors .= $this->displayError($this->l('Slide could not be added'));
} /* Update */
elseif (!$slide->update())
$errors .= $this->displayError($this->l('Slide could not be updated'));
} /* Deletes */
elseif (Tools::isSubmit('delete_id_slide'))
{
$slide = new HomeSlide((int)Tools::getValue('delete_id_slide'));
$res = $slide->delete();
if (!$res)
$this->_html .= $this->displayError('Could not delete');
$this->_html = $this->displayConfirmation($this->l('Slide deleted'));
}
/* Display errors if needed */
if (sizeof($errors))
$this->_html .= $this->displayError(implode('<br />', $errors));
elseif (Tools::isSubmit('submitSlide') && Tools::getValue('id_slide'))
$this->_html .= $this->displayConfirmation($this->l('Slide updated'));
elseif (Tools::isSubmit('submitSlide'))
$this->_html .= $this->displayConfirmation($this->l('Slide added'));
}
public function hookHome()
{
$slider = array(
'width' => Configuration::get('HOMESLIDER_WIDTH'),
'height' => Configuration::get('HOMESLIDER_HEIGHT'),
'speed' => Configuration::get('HOMESLIDER_SPEED'),
'pause' => Configuration::get('HOMESLIDER_PAUSE')
);
$slides = $this->getSlides(true);
if (!$slides)
return;
$this->context->smarty->assign('homeslider_slides', $slides);
$this->context->smarty->assign('homeslider', $slider);
return $this->display(__FILE__, 'homeslider.tpl');
}
public function hookHeader()
{
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js');
$this->context->controller->addJS($this->_path.'js/jquery.bxSlider.min.js');
$this->context->controller->addJS($this->_path.'js/homeslider.js');
$this->context->controller->addCSS($this->_path.'bx_styles.css');
}
public function hookBackOfficeTop()
{
/* Style & js for fieldset 'slides configuration' */
$html = '
<style>
#slides li {
list-style: none;
margin: 0 0 4px 0;
padding: 10px;
background-color: #F4E6C9;
border: #CCCCCC solid 1px;
color:#000;
}
</style>
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/jquery/jquery-ui-1.8.10.custom.min.js"></script>
<script type="text/javascript">
$(function() {
var $mySlides = $("#slides");
$mySlides.sortable({
opacity: 0.6,
cursor: "move",
update: function() {
var order = $(this).sortable("serialize") + "&action=updateSlidesPosition";
$.post("'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/ajax_'.$this->name.'.php?secure_key='.$this->secure_key.'", order);
}
});
$mySlides.hover(function() {
$(this).css("cursor","move");
},
function() {
$(this).css("cursor","auto");
});
});
</script>';
return $html;
}
public function getNextPosition()
{
$row = Db::getInstance()->getRow('
SELECT MAX(hss.`position`) AS `next_position`
FROM `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider` hs
WHERE hss.`id_slide` = hs.`id_slide` AND hs.`id_shop` = '.(int)$this->context->shop->getId()
);
return (++$row['next_position']);
}
public function getSlides($active = null)
{
$this->context = Context::getContext();
$idShop = $this->context->shop->getID();
$idLang = $this->context->language->id;
return Db::getInstance()->ExecuteS('
SELECT hs.`id_slide` AS id_slide, hssl.`image` as image, hss.`position` AS position, hss.`active` as active, hssl.`title` as title, hssl.`url` as url, hssl.`legend` as legend
FROM `'._DB_PREFIX_.'homeslider` hs, `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider_slides_lang` hssl
WHERE hs.`id_shop` = '.(int)$idShop. ((int)$idShop != 0 ? ' OR hs.`id_shop` = 0' : '').' AND hs.`id_slide` = hss.`id_slide` AND hss.`id_slide` = hssl.`id_slide` AND hs.`id_slide` = hssl.`id_slide`
AND hssl.`id_lang` = '.(int)$idLang.($active ? ' AND hss.`active` = 1' : '').'
ORDER BY hss.`position`
');
}
public function displayStatus($id_slide, $active)
{
$title = ((int)$active == 0 ? $this->l('Disabled') : $this->l('Enabled'));
$img = ((int)$active == 0 ? 'disabled.gif' : 'enabled.gif');
$html = '<a href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&changeStatus&id_slide='.(int)($id_slide).'" title="'.$title.'"><img src="'._PS_ADMIN_IMG_.''.$img.'" alt="" /></a>';
return $html;
}
public function slideExists($id_slide)
{
$req = 'SELECT hs.`id_slide`
FROM `'._DB_PREFIX_.'homeslider` hs
WHERE hs.`id_slide` = '.(int)$id_slide;
$row = Db::getInstance()->getRow($req);
return ($row);
}
}
+18
View File
@@ -0,0 +1,18 @@
<!-- Module HomeSlider -->
{if isset($homeslider)}
<script type="text/javascript">
var homeslider_loop = true;
var homeslider_speed = {$homeslider.speed};
var homeslider_pause = {$homeslider.pause};
</script>
{/if}
{if isset($homeslider_slides)}
<ul id="homeslider">
{foreach from=$homeslider_slides item=slide}
{if $slide.active}
<li><a href="{$slide.url}"><img src="modules/homeslider/images/{$slide.image}" alt="{$slide.legend}" height="{$homeslider.height}" width="{$homeslider.width}"></a></li>
{/if}
{/foreach}
</ul>
{/if}
<!-- /Module HomeSlider -->
+36
View File
@@ -0,0 +1,36 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;
+11
View File
@@ -0,0 +1,11 @@
$(function(){
$('#homeslider').bxSlider({
infiniteLoop: true,
hideControlOnEnd: true,
pager: true,
autoHover: true,
auto: true,
speed: homeslider_speed,
pause: homeslider_pause
});
});
+114
View File
@@ -0,0 +1,114 @@
/**
* jQuery bxSlider v3.0
* http://bxslider.com
*
* Copyright 2010, Steven Wanderski
* http://stevenwanderski.com
*
* Free to use and abuse under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
*/
(function($){$.fn.bxSlider=function(options){var defaults={mode:'horizontal',infiniteLoop:true,hideControlOnEnd:false,controls:true,speed:500,easing:'swing',pager:false,pagerSelector:null,pagerType:'full',pagerLocation:'bottom',pagerShortSeparator:'/',pagerActiveClass:'pager-active',nextText:'next',nextImage:'',nextSelector:null,prevText:'prev',prevImage:'',prevSelector:null,captions:false,captionsSelector:null,auto:false,autoDirection:'next',autoControls:false,autoControlsSelector:null,autoStart:true,autoHover:false,autoDelay:0,pause:3000,startText:'start',startImage:'',stopText:'stop',stopImage:'',ticker:false,tickerSpeed:5000,tickerDirection:'next',tickerHover:false,wrapperClass:'bx-wrapper',startingSlide:0,displaySlideQty:1,moveSlideQty:1,randomStart:false,onBeforeSlide:function(){},onAfterSlide:function(){},onLastSlide:function(){},onFirstSlide:function(){},onNextSlide:function(){},onPrevSlide:function(){},buildPager:null}
var options=$.extend(defaults,options);var base=this;var $parent='';var $origElement='';var $children='';var $outerWrapper='';var $firstChild='';var childrenWidth='';var childrenOuterWidth='';var wrapperWidth='';var wrapperHeight='';var $pager='';var interval='';var $autoControls='';var $stopHtml='';var $startContent='';var $stopContent='';var autoPlaying=true;var loaded=false;var childrenMaxWidth=0;var childrenMaxHeight=0;var currentSlide=0;var origLeft=0;var origTop=0;var origShowWidth=0;var origShowHeight=0;var tickerLeft=0;var tickerTop=0;var isWorking=false;var firstSlide=0;var lastSlide=$children.length-1;this.goToSlide=function(number,stopAuto){if(!isWorking){isWorking=true;currentSlide=number;options.onBeforeSlide(currentSlide,$children.length,$children.eq(currentSlide));if(typeof(stopAuto)=='undefined'){var stopAuto=true;}
if(stopAuto){if(options.auto){base.stopShow(true);}}
slide=number;if(slide==firstSlide){options.onFirstSlide(currentSlide,$children.length,$children.eq(currentSlide));}
if(slide==lastSlide){options.onLastSlide(currentSlide,$children.length,$children.eq(currentSlide));}
if(options.mode=='horizontal'){$parent.animate({'left':'-'+getSlidePosition(slide,'left')+'px'},options.speed,options.easing,function(){isWorking=false;options.onAfterSlide(currentSlide,$children.length,$children.eq(currentSlide));});}else if(options.mode=='vertical'){$parent.animate({'top':'-'+getSlidePosition(slide,'top')+'px'},options.speed,options.easing,function(){isWorking=false;options.onAfterSlide(currentSlide,$children.length,$children.eq(currentSlide));});}else if(options.mode=='fade'){setChildrenFade();}
checkEndControls();if(options.moveSlideQty>1){number=Math.floor(number/options.moveSlideQty);}
makeSlideActive(number);showCaptions();}}
this.goToNextSlide=function(stopAuto){if(typeof(stopAuto)=='undefined'){var stopAuto=true;}
if(stopAuto){if(options.auto){base.stopShow(true);}}
if(!options.infiniteLoop){if(!isWorking){var slideLoop=false;currentSlide=(currentSlide+(options.moveSlideQty));if(currentSlide<=lastSlide){checkEndControls();options.onNextSlide(currentSlide,$children.length,$children.eq(currentSlide));base.goToSlide(currentSlide);}else{currentSlide-=options.moveSlideQty;}}}else{if(!isWorking){isWorking=true;var slideLoop=false;currentSlide=(currentSlide+options.moveSlideQty);if(currentSlide>lastSlide){currentSlide=currentSlide%$children.length;slideLoop=true;}
options.onNextSlide(currentSlide,$children.length,$children.eq(currentSlide));options.onBeforeSlide(currentSlide,$children.length,$children.eq(currentSlide));if(options.mode=='horizontal'){var parentLeft=(options.moveSlideQty*childrenOuterWidth);$parent.animate({'left':'-='+parentLeft+'px'},options.speed,options.easing,function(){isWorking=false;if(slideLoop){$parent.css('left','-'+getSlidePosition(currentSlide,'left')+'px');}
options.onAfterSlide(currentSlide,$children.length,$children.eq(currentSlide));});}else if(options.mode=='vertical'){var parentTop=(options.moveSlideQty*childrenMaxHeight);$parent.animate({'top':'-='+parentTop+'px'},options.speed,options.easing,function(){isWorking=false;if(slideLoop){$parent.css('top','-'+getSlidePosition(currentSlide,'top')+'px');}
options.onAfterSlide(currentSlide,$children.length,$children.eq(currentSlide));});}else if(options.mode=='fade'){setChildrenFade();}
if(options.moveSlideQty>1){makeSlideActive(Math.ceil(currentSlide/options.moveSlideQty));}else{makeSlideActive(currentSlide);}
showCaptions();}}}
this.goToPreviousSlide=function(stopAuto){if(typeof(stopAuto)=='undefined'){var stopAuto=true;}
if(stopAuto){if(options.auto){base.stopShow(true);}}
if(!options.infiniteLoop){if(!isWorking){var slideLoop=false;currentSlide=currentSlide-options.moveSlideQty;if(currentSlide<0){currentSlide=0;if(options.hideControlOnEnd){$('.bx-prev',$outerWrapper).hide();}}
checkEndControls();options.onPrevSlide(currentSlide,$children.length,$children.eq(currentSlide));base.goToSlide(currentSlide);}}else{if(!isWorking){isWorking=true;var slideLoop=false;currentSlide=(currentSlide-(options.moveSlideQty));if(currentSlide<0){negativeOffset=(currentSlide%$children.length);if(negativeOffset==0){currentSlide=0;}else{currentSlide=($children.length)+negativeOffset;}
slideLoop=true;}
options.onPrevSlide(currentSlide,$children.length,$children.eq(currentSlide));options.onBeforeSlide(currentSlide,$children.length,$children.eq(currentSlide));if(options.mode=='horizontal'){var parentLeft=(options.moveSlideQty*childrenOuterWidth);$parent.animate({'left':'+='+parentLeft+'px'},options.speed,options.easing,function(){isWorking=false;if(slideLoop){$parent.css('left','-'+getSlidePosition(currentSlide,'left')+'px');}
options.onAfterSlide(currentSlide,$children.length,$children.eq(currentSlide));});}else if(options.mode=='vertical'){var parentTop=(options.moveSlideQty*childrenMaxHeight);$parent.animate({'top':'+='+parentTop+'px'},options.speed,options.easing,function(){isWorking=false;if(slideLoop){$parent.css('top','-'+getSlidePosition(currentSlide,'top')+'px');}
options.onAfterSlide(currentSlide,$children.length,$children.eq(currentSlide));});}else if(options.mode=='fade'){setChildrenFade();}
if(options.moveSlideQty>1){makeSlideActive(Math.ceil(currentSlide/options.moveSlideQty));}else{makeSlideActive(currentSlide);}
showCaptions();}}}
this.goToFirstSlide=function(stopAuto){if(typeof(stopAuto)=='undefined'){var stopAuto=true;}
base.goToSlide(firstSlide,stopAuto);}
this.goToLastSlide=function(){if(typeof(stopAuto)=='undefined'){var stopAuto=true;}
base.goToSlide(lastSlide,stopAuto);}
this.getCurrentSlide=function(){return currentSlide;}
this.getSlideCount=function(){return $children.length;}
this.stopShow=function(changeText){clearInterval(interval);if(typeof(changeText)=='undefined'){var changeText=true;}
if(changeText&&options.autoControls){$autoControls.html($startContent).removeClass('stop').addClass('start');autoPlaying=false;}}
this.startShow=function(changeText){if(typeof(changeText)=='undefined'){var changeText=true;}
setAutoInterval();if(changeText&&options.autoControls){$autoControls.html($stopContent).removeClass('start').addClass('stop');autoPlaying=true;}}
this.stopTicker=function(changeText){$parent.stop();if(typeof(changeText)=='undefined'){var changeText=true;}
if(changeText&&options.ticker){$autoControls.html($startContent).removeClass('stop').addClass('start');autoPlaying=false;}}
this.startTicker=function(changeText){if(options.mode=='horizontal'){if(options.tickerDirection=='next'){var stoppedLeft=parseInt($parent.css('left'));var remainingDistance=(origShowWidth+stoppedLeft)+$children.eq(0).width();}else if(options.tickerDirection=='prev'){var stoppedLeft=-parseInt($parent.css('left'));var remainingDistance=(stoppedLeft)-$children.eq(0).width();}
var finishingSpeed=(remainingDistance*options.tickerSpeed)/origShowWidth;moveTheShow(tickerLeft,remainingDistance,finishingSpeed);}else if(options.mode=='vertical'){if(options.tickerDirection=='next'){var stoppedTop=parseInt($parent.css('top'));var remainingDistance=(origShowHeight+stoppedTop)+$children.eq(0).height();}else if(options.tickerDirection=='prev'){var stoppedTop=-parseInt($parent.css('top'));var remainingDistance=(stoppedTop)-$children.eq(0).height();}
var finishingSpeed=(remainingDistance*options.tickerSpeed)/origShowHeight;moveTheShow(tickerTop,remainingDistance,finishingSpeed);if(typeof(changeText)=='undefined'){var changeText=true;}
if(changeText&&options.ticker){$autoControls.html($stopContent).removeClass('start').addClass('stop');autoPlaying=true;}}}
this.initShow=function(){$parent=$(this);$origElement=$parent.clone();$children=$parent.children();$outerWrapper='';$firstChild=$parent.children(':first');childrenWidth=$firstChild.width();childrenMaxWidth=0;childrenOuterWidth=$firstChild.outerWidth();childrenMaxHeight=0;wrapperWidth=getWrapperWidth();wrapperHeight=getWrapperHeight();isWorking=false;$pager='';currentSlide=0;origLeft=0;origTop=0;interval='';$autoControls='';$stopHtml='';$startContent='';$stopContent='';autoPlaying=true;loaded=false;origShowWidth=0;origShowHeight=0;tickerLeft=0;tickerTop=0;firstSlide=0;lastSlide=$children.length-1;$children.each(function(index){if($(this).outerHeight()>childrenMaxHeight){childrenMaxHeight=$(this).outerHeight();}
if($(this).outerWidth()>childrenMaxWidth){childrenMaxWidth=$(this).outerWidth();}});if(options.randomStart){var randomNumber=Math.floor(Math.random()*$children.length);currentSlide=randomNumber;origLeft=childrenOuterWidth*(options.moveSlideQty+randomNumber);origTop=childrenMaxHeight*(options.moveSlideQty+randomNumber);}else{currentSlide=options.startingSlide;origLeft=childrenOuterWidth*(options.moveSlideQty+options.startingSlide);origTop=childrenMaxHeight*(options.moveSlideQty+options.startingSlide);}
initCss();if(options.pager&&!options.ticker){if(options.pagerType=='full'){showPager('full');}else if(options.pagerType=='short'){showPager('short');}}
if(options.controls&&!options.ticker){setControlsVars();}
if(options.auto||options.ticker){if(options.autoControls){setAutoControlsVars();}
if(options.autoStart){setTimeout(function(){base.startShow(true);},options.autoDelay);}else{base.stopShow(true);}
if(options.autoHover&&!options.ticker){setAutoHover();}}
if(options.moveSlideQty>1){makeSlideActive(Math.ceil(currentSlide/options.moveSlideQty));}else{makeSlideActive(currentSlide);}
checkEndControls();if(options.captions){showCaptions();}
options.onAfterSlide(currentSlide,$children.length,$children.eq(currentSlide));}
this.destroyShow=function(){clearInterval(interval);$('.bx-next, .bx-prev, .bx-pager, .bx-auto',$outerWrapper).remove();$parent.unwrap().unwrap().removeAttr('style');$parent.children().removeAttr('style').not('.pager').remove();$children.removeClass('pager');}
this.reloadShow=function(){base.destroyShow();base.initShow();}
function initCss(){setChildrenLayout(options.startingSlide);if(options.mode=='horizontal'){$parent.wrap('<div class="'+options.wrapperClass+'" style="width:'+wrapperWidth+'px; position:relative;"></div>').wrap('<div class="bx-window" style="position:relative; overflow:hidden; width:'+wrapperWidth+'px;"></div>').css({width:'999999px',position:'relative',left:'-'+(origLeft)+'px'});$parent.children().css({width:childrenWidth,'float':'left',listStyle:'none'});$outerWrapper=$parent.parent().parent();$children.addClass('pager');}else if(options.mode=='vertical'){$parent.wrap('<div class="'+options.wrapperClass+'" style="width:'+childrenMaxWidth+'px; position:relative;"></div>').wrap('<div class="bx-window" style="width:'+childrenMaxWidth+'px; height:'+wrapperHeight+'px; position:relative; overflow:hidden;"></div>').css({height:'999999px',position:'relative',top:'-'+(origTop)+'px'});$parent.children().css({listStyle:'none',height:childrenMaxHeight});$outerWrapper=$parent.parent().parent();$children.addClass('pager');}else if(options.mode=='fade'){$parent.wrap('<div class="'+options.wrapperClass+'" style="width:'+childrenMaxWidth+'px; position:relative;"></div>').wrap('<div class="bx-window" style="height:'+childrenMaxHeight+'px; width:'+childrenMaxWidth+'px; position:relative; overflow:hidden;"></div>');$parent.children().css({listStyle:'none',position:'absolute',top:0,left:0,zIndex:98});$outerWrapper=$parent.parent().parent();$children.not(':eq('+currentSlide+')').fadeTo(0,0);$children.eq(currentSlide).css('zIndex',99);}
if(options.captions&&options.captionsSelector==null){$outerWrapper.append('<div class="bx-captions"></div>');}}
function setChildrenLayout(){if(options.mode=='horizontal'||options.mode=='vertical'){var $prependedChildren=getArraySample($children,0,options.moveSlideQty,'backward');$.each($prependedChildren,function(index){$parent.prepend($(this));});var totalNumberAfterWindow=($children.length+options.moveSlideQty)-1;var pagerExcess=$children.length-options.displaySlideQty;var numberToAppend=totalNumberAfterWindow-pagerExcess;var $appendedChildren=getArraySample($children,0,numberToAppend,'forward');if(options.infiniteLoop){$.each($appendedChildren,function(index){$parent.append($(this));});}}}
function setControlsVars(){if(options.nextImage!=''){nextContent=options.nextImage;nextType='image';}else{nextContent=options.nextText;nextType='text';}
if(options.prevImage!=''){prevContent=options.prevImage;prevType='image';}else{prevContent=options.prevText;prevType='text';}
showControls(nextType,nextContent,prevType,prevContent);}
function setAutoInterval(){if(options.auto){if(!options.infiniteLoop){if(options.autoDirection=='next'){interval=setInterval(function(){currentSlide+=options.moveSlideQty;if(currentSlide>lastSlide){currentSlide=currentSlide%$children.length;}
base.goToSlide(currentSlide,false);},options.pause);}else if(options.autoDirection=='prev'){interval=setInterval(function(){currentSlide-=options.moveSlideQty;if(currentSlide<0){negativeOffset=(currentSlide%$children.length);if(negativeOffset==0){currentSlide=0;}else{currentSlide=($children.length)+negativeOffset;}}
base.goToSlide(currentSlide,false);},options.pause);}}else{if(options.autoDirection=='next'){interval=setInterval(function(){base.goToNextSlide(false);},options.pause);}else if(options.autoDirection=='prev'){interval=setInterval(function(){base.goToPreviousSlide(false);},options.pause);}}}else if(options.ticker){options.tickerSpeed*=10;$('.pager',$outerWrapper).each(function(index){origShowWidth+=$(this).width();origShowHeight+=$(this).height();});if(options.tickerDirection=='prev'&&options.mode=='horizontal'){$parent.css('left','-'+(origShowWidth+origLeft)+'px');}else if(options.tickerDirection=='prev'&&options.mode=='vertical'){$parent.css('top','-'+(origShowHeight+origTop)+'px');}
if(options.mode=='horizontal'){tickerLeft=parseInt($parent.css('left'));moveTheShow(tickerLeft,origShowWidth,options.tickerSpeed);}else if(options.mode=='vertical'){tickerTop=parseInt($parent.css('top'));moveTheShow(tickerTop,origShowHeight,options.tickerSpeed);}
if(options.tickerHover){setTickerHover();}}}
function moveTheShow(leftCss,distance,speed){if(options.mode=='horizontal'){if(options.tickerDirection=='next'){$parent.animate({'left':'-='+distance+'px'},speed,'linear',function(){$parent.css('left',leftCss);moveTheShow(leftCss,origShowWidth,options.tickerSpeed);});}else if(options.tickerDirection=='prev'){$parent.animate({'left':'+='+distance+'px'},speed,'linear',function(){$parent.css('left',leftCss);moveTheShow(leftCss,origShowWidth,options.tickerSpeed);});}}else if(options.mode=='vertical'){if(options.tickerDirection=='next'){$parent.animate({'top':'-='+distance+'px'},speed,'linear',function(){$parent.css('top',leftCss);moveTheShow(leftCss,origShowHeight,options.tickerSpeed);});}else if(options.tickerDirection=='prev'){$parent.animate({'top':'+='+distance+'px'},speed,'linear',function(){$parent.css('top',leftCss);moveTheShow(leftCss,origShowHeight,options.tickerSpeed);});}}}
function setAutoControlsVars(){if(options.startImage!=''){startContent=options.startImage;startType='image';}else{startContent=options.startText;startType='text';}
if(options.stopImage!=''){stopContent=options.stopImage;stopType='image';}else{stopContent=options.stopText;stopType='text';}
showAutoControls(startType,startContent,stopType,stopContent);}
function setAutoHover(){$outerWrapper.find('.bx-window').hover(function(){if(autoPlaying){base.stopShow(false);}},function(){if(autoPlaying){base.startShow(false);}});}
function setTickerHover(){$parent.hover(function(){if(autoPlaying){base.stopTicker(false);}},function(){if(autoPlaying){base.startTicker(false);}});}
function setChildrenFade(){$children.not(':eq('+currentSlide+')').fadeTo(options.speed,0).css('zIndex',98);$children.eq(currentSlide).css('zIndex',99).fadeTo(options.speed,1,function(){isWorking=false;if(jQuery.browser.msie){$children.eq(currentSlide).get(0).style.removeAttribute('filter');}
options.onAfterSlide(currentSlide,$children.length,$children.eq(currentSlide));});};function makeSlideActive(number){if(options.pagerType=='full'&&options.pager){$('a',$pager).removeClass(options.pagerActiveClass);$('a',$pager).eq(number).addClass(options.pagerActiveClass);}else if(options.pagerType=='short'&&options.pager){$('.bx-pager-current',$pager).html(currentSlide+1);}}
function showControls(nextType,nextContent,prevType,prevContent){var $nextHtml=$('<a href="" class="bx-next"></a>');var $prevHtml=$('<a href="" class="bx-prev"></a>');if(nextType=='text'){$nextHtml.html(nextContent);}else{$nextHtml.html('<img src="'+nextContent+'" />');}
if(prevType=='text'){$prevHtml.html(prevContent);}else{$prevHtml.html('<img src="'+prevContent+'" />');}
if(options.prevSelector){$(options.prevSelector).append($prevHtml);}else{$outerWrapper.append($prevHtml);}
if(options.nextSelector){$(options.nextSelector).append($nextHtml);}else{$outerWrapper.append($nextHtml);}
$nextHtml.click(function(){base.goToNextSlide();return false;});$prevHtml.click(function(){base.goToPreviousSlide();return false;});}
function showPager(type){var pagerQty=$children.length;if(options.moveSlideQty>1){if($children.length%options.moveSlideQty!=0){pagerQty=Math.ceil($children.length/options.moveSlideQty);}else{pagerQty=$children.length/options.moveSlideQty;}}
var pagerString='';if(options.buildPager){for(var i=0;i<pagerQty;i++){pagerString+=options.buildPager(i,$children.eq(i*options.moveSlideQty));}}else if(type=='full'){for(var i=1;i<=pagerQty;i++){pagerString+='<a href="" class="pager-link pager-'+i+'">'+i+'</a>';}}else if(type=='short'){pagerString='<span class="bx-pager-current">'+(options.startingSlide+1)+'</span> '+options.pagerShortSeparator+' <span class="bx-pager-total">'+$children.length+'<span>';}
if(options.pagerSelector){$(options.pagerSelector).append(pagerString);$pager=$(options.pagerSelector);}else{var $pagerContainer=$('<div class="bx-pager"></div>');$pagerContainer.append(pagerString);if(options.pagerLocation=='top'){$outerWrapper.prepend($pagerContainer);}else if(options.pagerLocation=='bottom'){$outerWrapper.append($pagerContainer);}
$pager=$('.bx-pager',$outerWrapper);}
$pager.children().click(function(){if(options.pagerType=='full'){var slideIndex=$pager.children().index(this);if(options.moveSlideQty>1){slideIndex*=options.moveSlideQty;}
base.goToSlide(slideIndex);}
return false;});}
function showCaptions(){var caption=$('img',$children.eq(currentSlide)).attr('title');if(caption!=''){if(options.captionsSelector){$(options.captionsSelector).html(caption);}else{$('.bx-captions',$outerWrapper).html(caption);}}else{if(options.captionsSelector){$(options.captionsSelector).html(' ');}else{$('.bx-captions',$outerWrapper).html(' ');}}}
function showAutoControls(startType,startContent,stopType,stopContent){$autoControls=$('<a href="" class="bx-start"></a>');if(startType=='text'){$startContent=startContent;}else{$startContent='<img src="'+startContent+'" />';}
if(stopType=='text'){$stopContent=stopContent;}else{$stopContent='<img src="'+stopContent+'" />';}
if(options.autoControlsSelector){$(options.autoControlsSelector).append($autoControls);}else{$outerWrapper.append('<div class="bx-auto"></div>');$('.bx-auto',$outerWrapper).html($autoControls);}
$autoControls.click(function(){if(options.ticker){if($(this).hasClass('stop')){base.stopTicker();}else if($(this).hasClass('start')){base.startTicker();}}else{if($(this).hasClass('stop')){base.stopShow(true);}else if($(this).hasClass('start')){base.startShow(true);}}
return false;});}
function checkEndControls(){if(!options.infiniteLoop&&options.hideControlOnEnd){if(currentSlide==firstSlide){$('.bx-prev',$outerWrapper).hide();}else{$('.bx-prev',$outerWrapper).show();}
if(currentSlide==lastSlide){$('.bx-next',$outerWrapper).hide();}else{$('.bx-next',$outerWrapper).show();}}}
function getSlidePosition(number,side){if(side=='left'){var position=$('.pager',$outerWrapper).eq(number).position().left;}else if(side=='top'){var position=$('.pager',$outerWrapper).eq(number).position().top;}
return position;}
function getWrapperWidth(){var wrapperWidth=$firstChild.outerWidth()*options.displaySlideQty;return wrapperWidth;}
function getWrapperHeight(){var wrapperHeight=$firstChild.outerHeight()*options.displaySlideQty;return wrapperHeight;}
function getArraySample(array,start,length,direction){var sample=[];var loopLength=length;var startPopulatingArray=false;if(direction=='backward'){array=$.makeArray(array);array.reverse();}
while(loopLength>0){$.each(array,function(index,val){if(loopLength>0){if(!startPopulatingArray){if(index==start){startPopulatingArray=true;sample.push($(this).clone());loopLength--;}}else{sample.push($(this).clone());loopLength--;}}else{return false;}});}
return sample;}
this.each(function(){base.initShow();});return this;}
jQuery.fx.prototype.cur=function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null)){return this.elem[this.prop];}
var r=parseFloat(jQuery.css(this.elem,this.prop));return r;}})(jQuery);
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB