name = 'infiniteajax'; $this->tab = 'front_office_features'; $this->version = '1.3.1'; $this->author = 'Mellow (PrestaShop Forum Member)'; $this->page = basename(__FILE__, '.php'); $this->displayName = $this->l('Infinite Ajax Scroll'); $this->description = $this->l('Infinite scroll with automatic pagination'); parent::__construct(); } function install() { if (!parent::install() || !$this->registerHook('header')) return false; Configuration::updateValue('PS_INFINITE_AJAX_TRESHOLD', 0); Configuration::updateValue('PS_INFINITE_AJAX_HISTORY', 1); Configuration::updateValue('PS_INFINITE_AJAX_BLKLAYRD', 0); Configuration::updateValue('PS_INFINITE_AJAX_LOADING', ''); Configuration::updateValue('PS_INFINITE_AJAX_TRIGGERPAGE', ''); Configuration::updateValue('PS_INFINITE_AJAX_TRIGGER', ''); Configuration::updateValue('PS_INFINITE_AJAX_NONELEFT', ''); Configuration::updateValue('PS_INFINITE_AJAX_NONELEFTLINK', 0); Configuration::updateValue('PS_INFINITE_AJAX_LOADER', 'modules/infiniteajax/images/loader.gif'); Configuration::updateValue('PS_INFINITE_AJAX_PRODLISTELE', 'product_list,ajax_block_product,pagination,pagination_next'); Configuration::updateValue('PS_INFINITE_AJAX_ONRENDERCOMP', 'function(){if(typeof(ajaxCart)!=\'undefined\'){ajaxCart.overrideButtonsInThePage();ajaxCart.refresh()}if(typeof(reloadProductComparison)==\'function\')reloadProductComparison()}'); return true; } function uninstall() { Configuration::deleteByName('PS_INFINITE_AJAX_TRESHOLD'); Configuration::deleteByName('PS_INFINITE_AJAX_HISTORY'); Configuration::deleteByName('PS_INFINITE_AJAX_BLKLAYRD'); Configuration::deleteByName('PS_INFINITE_AJAX_LOADING'); Configuration::deleteByName('PS_INFINITE_AJAX_TRIGGERPAGE'); Configuration::deleteByName('PS_INFINITE_AJAX_TRIGGER'); Configuration::deleteByName('PS_INFINITE_AJAX_NONELEFT'); Configuration::deleteByName('PS_INFINITE_AJAX_NONELEFTLINK'); Configuration::deleteByName('PS_INFINITE_AJAX_LOADER'); Configuration::deleteByName('PS_INFINITE_AJAX_PRODLISTELE'); Configuration::deleteByName('PS_INFINITE_AJAX_ONRENDERCOMP'); if (!parent::uninstall() || !$this->unregisterHook('header')) return false; return true; } public function getLoaders() { $thedir = dirname(__FILE__).'/images/'; $dirimages = opendir($thedir); while ($isitem = readdir($dirimages)) { $theimages[] = $isitem; } sort($theimages); foreach ($theimages as $theimage) if ($theimage != '.' && $theimage != '..' && $theimage != 'Thumbs.db' && $theimage != 'index.php' && $theimage != 'icon' && !is_dir($theimage)) $loaders[] = $theimage; return $loaders; } public function isPhoneDevice() { if (!class_exists('Mobile_Detect')) { if (version_compare(_PS_VERSION_,'1.5','>')) require_once(_PS_TOOL_DIR_.'mobile_Detect/Mobile_Detect.php'); else require_once('Mobile_Detect.php'); } $this->mobile_detect = new Mobile_Detect(); $this->phone_device = false; if ($this->mobile_detect->isMobile() && !$this->mobile_detect->isTablet()) $this->phone_device = true; // * Debug * //if ($this->phone_device == true) echo "This is a Phone or a SmartPhone"; //if ($this->mobile_detect->isTablet()) echo "This is a Tablet"; return $this->phone_device; } function hookheader($params) { global $smarty, $cookie; if ($this->isPhoneDevice()) return; if (version_compare(_PS_VERSION_,'1.5','>')) { $page_name = Tools::getValue('controller'); $id_shop = (int) Context::getContext()->shop->id; $pages_with_productlist = array("category", "manufacturer", "supplier", "search", "pricesdrop", "newproducts", "bestsales"); } else { $pathinfo = pathinfo(__FILE__); $page_name = basename($_SERVER['PHP_SELF'], '.'.$pathinfo['extension']); $id_shop = 0; $pages_with_productlist = array("category", "manufacturer", "supplier", "search", "prices-drop", "new-products", "best-sales"); } // Si il s'agit d'une page affichant une liste de produits if (in_array($page_name, $pages_with_productlist)) { if ($page_name == "manufacturer" AND !((int)Tools::getValue('id_manufacturer') > 0)) return; if ($page_name == "supplier" AND !((int)Tools::getValue('id_supplier') > 0)) return; $blocklayered_activated = false; $isactive_blocklayered = false; if ($page_name == "category") { $id_category = (int)Tools::getValue('id_category'); if (version_compare(_PS_VERSION_,'1.5','>')) $blocklayered_activated = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue("SELECT m.id_module FROM "._DB_PREFIX_."module m, "._DB_PREFIX_."module_shop s WHERE m.name = 'blocklayered' AND m.active = 1 AND m.id_module = s.id_module AND s.id_shop = ".$id_shop); else $blocklayered_activated = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue("SELECT id_module FROM "._DB_PREFIX_."module WHERE name = 'blocklayered' AND active = 1"); if ($blocklayered_activated == true) $isactive_blocklayered = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT id_category FROM '._DB_PREFIX_.'layered_category WHERE id_category = '.$id_category.' AND id_shop = '.$id_shop); // Si il s'agit d'une catégorie avec navigation à facettes, et que l'option est désactivée dans le module if ($isactive_blocklayered == true AND Configuration::get('PS_INFINITE_AJAX_BLKLAYRD') == 0) return; } if (version_compare(_PS_VERSION_,'1.5','>')) { $this->context->controller->addJS(($this->_path).'jquery-ias.js'); $this->context->controller->addCSS(($this->_path).'css/jquery.ias.css', 'all'); } else { Tools::addJS(($this->_path).'jquery-ias.js'); Tools::addCSS(($this->_path).'css/jquery.ias.css', 'all'); } $ListElements = explode(',', Configuration::get('PS_INFINITE_AJAX_PRODLISTELE')); $tresholdMargin = Configuration::get('PS_INFINITE_AJAX_TRESHOLD'); $triggerPageThreshold = Configuration::get('PS_INFINITE_AJAX_TRIGGERPAGE'); $trigger = Configuration::get('PS_INFINITE_AJAX_TRIGGER', (int)$cookie->id_lang); $noneleft = Configuration::get('PS_INFINITE_AJAX_NONELEFT', (int)$cookie->id_lang); $loader = Configuration::get('PS_INFINITE_AJAX_LOADER'); $loadingtext = Configuration::get('PS_INFINITE_AJAX_LOADING', (int)$cookie->id_lang); $RenderCompleteFunction = Configuration::get('PS_INFINITE_AJAX_ONRENDERCOMP'); return " "; } return; } public function getContent() { $this->_html = '

'.$this->l('Settings').' : '.$this->displayName.'

'; $errors = ''; if (Tools::isSubmit('submitConfig')) { $languages = Language::getLanguages(); $loadtext = array(); $triggertext = array(); $nonelefttext = array(); foreach ($languages AS $language) { $loadtext[$language['id_lang']] = $_POST['loadtxt_'.$language['id_lang']]; $triggertext[$language['id_lang']] = $_POST['trigtxt_'.$language['id_lang']]; $nonelefttext[$language['id_lang']] = $_POST['nonetxt_'.$language['id_lang']]; } $PS_INFINITE_AJAX_PRODLISTELE = Tools::getValue('PRODLSTID').','.Tools::getValue('PRODCLASS').','.Tools::getValue('PRODPAGID').','.Tools::getValue('PRODNEXID'); if (!Configuration::updateValue('PS_INFINITE_AJAX_TRESHOLD', Tools::getValue('PS_INFINITE_AJAX_TRESHOLD'))) $this->_html .= '
'.$this->l('Cannot update settings').'
'; elseif (!Configuration::updateValue('PS_INFINITE_AJAX_TRIGGERPAGE', Tools::getValue('PS_INFINITE_AJAX_TRIGGERPAGE'))) $this->_html .= '
'.$this->l('Cannot update settings').'
'; elseif (!Configuration::updateValue('PS_INFINITE_AJAX_HISTORY', Tools::getValue('PS_INFINITE_AJAX_HISTORY'))) $this->_html .= '
'.$this->l('Cannot update settings').'
'; elseif (!Configuration::updateValue('PS_INFINITE_AJAX_NONELEFTLINK', Tools::getValue('PS_INFINITE_AJAX_NONELEFTLINK'))) $this->_html .= '
'.$this->l('Cannot update settings').'
'; elseif (!Configuration::updateValue('PS_INFINITE_AJAX_BLKLAYRD', Tools::getValue('PS_INFINITE_AJAX_BLKLAYRD'))) $this->_html .= '
'.$this->l('Cannot update settings').'
'; elseif (!Configuration::updateValue('PS_INFINITE_AJAX_LOADING', $loadtext)) $this->_html .= '
'.$this->l('Cannot update settings').'
'; elseif (!Configuration::updateValue('PS_INFINITE_AJAX_TRIGGER', $triggertext)) $this->_html .= '
'.$this->l('Cannot update settings').'
'; elseif (!Configuration::updateValue('PS_INFINITE_AJAX_NONELEFT', $nonelefttext)) $this->_html .= '
'.$this->l('Cannot update settings').'
'; elseif (!Configuration::updateValue('PS_INFINITE_AJAX_LOADER', Tools::getValue('PS_INFINITE_AJAX_LOADER'))) $this->_html .= '
'.$this->l('Cannot update settings').'
'; elseif (!Configuration::updateValue('PS_INFINITE_AJAX_PRODLISTELE', $PS_INFINITE_AJAX_PRODLISTELE)) $this->_html .= '
'.$this->l('Cannot update settings').'
'; elseif (!Configuration::updateValue('PS_INFINITE_AJAX_ONRENDERCOMP', str_replace(array("\r\n", "\r", "\n"), ' ', Tools::getValue('PS_INFINITE_AJAX_ONRENDERCOMP')))) $this->_html .= '
'.$this->l('Cannot update settings').'
'; else $this->_html .= '
'.$this->l('Settings updated').'
'; } $this->_displayForm(); return $this->_html; } private function _displayForm() { global $cookie; /* Language */ $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT')); $languages = Language::getLanguages(false); $divLangName = 'loadtxt¤trigtxt¤nonetxt'; $ListElements = explode(',', Configuration::get('PS_INFINITE_AJAX_PRODLISTELE')); $this->_html .='
'.$this->l('Behavior :').'

'.$this->l('The history uses hashes (in the format : #/page-x) to remember the last viewed page. When a visitor hits the back button after visiting an item from that page, it will load all items up to that last page and scrolls it into view. The use of hashes can be problematic in some cases, in which case you can disable this feature.').'

'.$this->l('pixels').'

'.$this->l('Setting a treshold margin of -N means that next page will start loading N pixel before the last item has scrolled into view. A positive margin means that next page will start loading N pixels after the last item.').'

'.$this->l('Animated image to display when loading next page (relative to Prestashop instalation folder , default : modules/infiniteajax/images/loader.gif )').'

    '; foreach ( $this->getLoaders() as $id => $loader ) { $loaderimg = 'modules/infiniteajax/images/'.$loader; if (Configuration::get('PS_INFINITE_AJAX_LOADER') == $loaderimg) $check = 'checked = "checked"'; else $check = ''; $this->_html .= '
  • '; } $this->_html .= '
'; foreach ($languages as $language) $this->_html .= '

'.$this->l('Text to display when loading next page (default : nothing )').'

'; $this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'loadtxt', true); $this->_html .= '
'.$this->l('pages').'

'.$this->l('Pages will be loaded automatically until this limit, then a link will be displayed. Users will have to manually trigger the loading of the next page by clicking this link. (default: none / disabled)').'

'; foreach ($languages as $language) $this->_html .= '

'.$this->l('Default: empty - If empty and auto loading limit set, default will be \'Afficher plus de produits\'').'

'; $this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'trigtxt', true); $this->_html .= '
'; foreach ($languages as $language) $this->_html .= '

'.$this->l('Text to display when the last page is reached (exemple: \'No more pages to load\' - default: none)').'

'; $this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'nonetxt', true); $this->_html .= '

'.$this->l('Add a \'Scroll to top\' link to \'Last page\' text (if set)').'

'.$this->l('Before activating this option, YOU MUST place the modified blocklayered.js file in \'/js/modules/blocklayered/\' folder of your theme') .'
www.prestashop.com/forums/topic/232911-infinite-ajax-scroll/#entry1225025


'.$this->l('Product list elements (Configure according to your theme)').'

'.$this->l('The id of the element containing the product list (in product-list.tpl) (default : \'product_list\')').'

'.$this->l('The class of the product block elements (in product-list.tpl) (default : \'ajax_block_product\')').'

'.$this->l('The id of the elements containing the pagination block (in pagination.tpl) (default : \'pagination\')').'

'.$this->l('The id of the pagination \'Next\' (in pagination.tpl) (default : \'pagination_next\')').'


'.$this->l('CallBack function :').'

'.$this->l('This javascript function will be executed at the end of loading a new page.').'
' .$this->l('Default : ').'function(){if(typeof(ajaxCart)!=\'undefined\'){ajaxCart.overrideButtonsInThePage();ajaxCart.refresh()}if(typeof(reloadProductComparison)==\'function\')reloadProductComparison()}

'.$this->l('This can be useful when you have a javascript function that normally performs some actions on the items using the "document.ready" event. When loading items from a new page using this module, the "document.ready" handler is not called. Use this event instead.').' Documentation : github.com/webcreate/Infinite-Ajax-Scroll

Nota : ' .$this->l('It is best to compress your js function before inserting here. See').' javascriptcompressor.com
ex : function(){$(\'a.product_image\').hoverIntent(function(){$(this).parent(\'div.product_desc\').stop()},function(){return})}


 
'; $this->_html .= " "; } } ?>