-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
290 additions
and
81 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
app/code/local/TLaziuk/LazyLoad/Block/System/Config/Form/Field/Block.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
class TLaziuk_LazyLoad_Block_System_Config_Form_Field_Block | ||
extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract | ||
{ | ||
protected function _prepareToRender() | ||
{ | ||
$this->addColumn('name', array( | ||
'label' => $this->__('Name in Layout'), | ||
)); | ||
|
||
$this->addColumn('type', array( | ||
'label' => $this->__('Type'), | ||
'renderer' => $this->_getTypeRenderer(), | ||
)); | ||
|
||
return parent::_prepareToRender(); | ||
} | ||
|
||
protected $_typeRenderer = null; | ||
|
||
protected function _getTypeRenderer() | ||
{ | ||
if (is_null($this->_typeRenderer)) { | ||
$this->_typeRenderer = $this->getLayout()->createBlock( | ||
'tlaziuk_lazyload/system_config_form_field_type', | ||
'', | ||
array( | ||
'is_render_to_js_template' => true, | ||
) | ||
); | ||
} | ||
return $this->_typeRenderer; | ||
} | ||
|
||
protected function _prepareArrayRow(Varien_Object $row) | ||
{ | ||
$row->setData( | ||
'option_extra_attr_' . $this->_getTypeRenderer()->calcOptionHash($row->getData('type')), | ||
'selected="selected"' | ||
); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/code/local/TLaziuk/LazyLoad/Block/System/Config/Form/Field/Type.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
class TLaziuk_LazyLoad_Block_System_Config_Form_Field_Type | ||
extends Mage_Core_Block_Html_Select | ||
{ | ||
protected function _beforeToHtml() | ||
{ | ||
$this->setOptions(Mage::getSingleton('tlaziuk_lazyload/system_config_source_type')->toOptionArray()); | ||
|
||
return parent::_beforeToHtml(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<?php | ||
abstract class TLaziuk_LazyLoad_Helper_Abstract | ||
extends Mage_Core_Helper_Abstract | ||
{ | ||
const XML_PATH_ALL = 'advanced/tlaziuk_lazyload/all'; | ||
const XML_PATH_ATTRIBUTE = 'advanced/tlaziuk_lazyload/attribute'; | ||
const XML_PATH_BLOCK = 'advanced/tlaziuk_lazyload/block'; | ||
const XML_PATH_ENABLED = 'advanced/tlaziuk_lazyload/enabled'; | ||
const XML_PATH_MODULE = 'advanced/tlaziuk_lazyload/module'; | ||
const XML_PATH_PATTERN = 'advanced/tlaziuk_lazyload/pattern'; | ||
const XML_PATH_PLACEHOLDER = 'advanced/tlaziuk_lazyload/placeholder'; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAttribute() | ||
{ | ||
return Mage::getStoreConfig(self::XML_PATH_ATTRIBUTE); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getPlaceholder() | ||
{ | ||
return Mage::getStoreConfig(self::XML_PATH_PLACEHOLDER); | ||
} | ||
|
||
/** @var string */ | ||
protected $_pattern = null; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getPattern() | ||
{ | ||
if (!is_string($this->_pattern)) { | ||
$this->_pattern = Mage::getStoreConfig(self::XML_PATH_PATTERN); | ||
} | ||
return $this->_pattern; | ||
} | ||
|
||
/** | ||
* @param string $pattern | ||
* | ||
* @return self | ||
*/ | ||
public function setPattern($pattern) | ||
{ | ||
$this->_pattern = $pattern; | ||
return $this; | ||
} | ||
|
||
/** @var callable */ | ||
protected $_callback = null; | ||
|
||
/** | ||
* @return callable | ||
*/ | ||
public function getCallback() | ||
{ | ||
if (!is_callable($this->_callback)) { | ||
$this->_callback = function ($matches) { | ||
if (strpos($matches[0], $this->getAttribute()) === false) { | ||
return "<img{$matches[1]}{$this->getAttribute()}={$matches[2]}{$matches[3]}{$matches[2]} src={$matches[2]}{$this->getPlaceholder()}{$matches[2]}{$matches[4]}>"; | ||
} | ||
return $matches[0]; | ||
}; | ||
} | ||
return $this->_callback; | ||
} | ||
|
||
/** | ||
* @param callable $callback | ||
* | ||
* @return self | ||
*/ | ||
public function setCallback(callable $callback) | ||
{ | ||
$this->_callback = $callback; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function isEnabled() | ||
{ | ||
return Mage::getStoreConfigFlag(self::XML_PATH_ENABLED); | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function isAll() | ||
{ | ||
return Mage::getStoreConfigFlag(self::XML_PATH_ALL); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getModule() | ||
{ | ||
return explode(',', Mage::getStoreConfig(self::XML_PATH_MODULE)); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getBlock() | ||
{ | ||
$res = array( | ||
TLaziuk_LazyLoad_Model_System_Config_Source_Type::VAL_EXCLUDE => array(), | ||
TLaziuk_LazyLoad_Model_System_Config_Source_Type::VAL_INCLUDE => array(), | ||
); | ||
|
||
try { | ||
if (is_array($arr = Zend_Serializer::unserialize(Mage::getStoreConfig(self::XML_PATH_BLOCK)))) { | ||
foreach ($arr as $row) { | ||
if ($row['type'] == TLaziuk_LazyLoad_Model_System_Config_Source_Type::VAL_EXCLUDE) { | ||
$res[TLaziuk_LazyLoad_Model_System_Config_Source_Type::VAL_EXCLUDE][] = $row['name']; | ||
} elseif ($row['type'] == TLaziuk_LazyLoad_Model_System_Config_Source_Type::VAL_INCLUDE) { | ||
$res[TLaziuk_LazyLoad_Model_System_Config_Source_Type::VAL_INCLUDE][] = $row['name']; | ||
} | ||
} | ||
} | ||
} catch (Exception $exception) { | ||
Mage::logException($exception); | ||
} | ||
|
||
return $res; | ||
} | ||
|
||
/** | ||
* overwrite default isModuleEnabled method | ||
* | ||
* @param string $moduleName (optional) full module name | ||
* | ||
* @return boolean | ||
*/ | ||
public function isModuleEnabled($moduleName = null) | ||
{ | ||
if ($moduleName === $this->_getModuleName()) { | ||
return $this->isEnabled() && parent::isModuleEnabled($moduleName); | ||
} | ||
return parent::isModuleEnabled($moduleName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/code/local/TLaziuk/LazyLoad/Model/System/Config/Source/Type.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
class TLaziuk_LazyLoad_Model_System_Config_Source_Type | ||
{ | ||
const VAL_INCLUDE = 'include'; | ||
const VAL_EXCLUDE = 'exclude'; | ||
|
||
public function toOptionArray() | ||
{ | ||
$helper = Mage::helper('tlaziuk_lazyload'); | ||
|
||
return array( | ||
array('value' => self::VAL_INCLUDE, 'label' => $helper->__('Include')), | ||
array('value' => self::VAL_EXCLUDE, 'label' => $helper->__('Exclude')), | ||
); | ||
} | ||
public function toArray() | ||
{ | ||
$res = array(); | ||
|
||
foreach ($this->toOptionArray() as $opt) { | ||
$res[$opt['value']] = $opt['label']; | ||
} | ||
|
||
return $res; | ||
} | ||
} |
Oops, something went wrong.