Библиотека для cis, online, cms1
This commit is contained in:
commit
3c2e614d87
269 changed files with 39854 additions and 0 deletions
87
core/widgets/widget.php
Normal file
87
core/widgets/widget.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
require_once 'core/json.php';
|
||||
|
||||
function forceUrl($name)
|
||||
{
|
||||
if(is_callable($name)) {
|
||||
return call_user_func($name);
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Êëàññ äëÿ ãåíåðàöèè è óïðàâëåíèÿ àêòèâíûìè êîìïîíåíòàìè ñòðàíèöû
|
||||
* Êîìïîíåíò ñîñòîèò èç ñëåäóþùèõ ÷àñòåé
|
||||
* PHP - Óïðàâëåíèå êîìïîíåíòîì (Ãåíåðàöèÿ, Èíèöèàëèçàöèÿ, Îáðàáîòêà ñîáûòèé)
|
||||
* HTML - Íåîáõîäèìûå øàáëîíû
|
||||
* CSS - Ñòèëè
|
||||
* Javascript - Êëèåíòñêàÿ ÷àñòü óïðàâëåíèÿ êîìïîíåíòîì
|
||||
*/
|
||||
class Widget
|
||||
{
|
||||
private static $prefix = "_g";
|
||||
private static $idx = 0;
|
||||
private $id;
|
||||
public $data = array();
|
||||
public $view;
|
||||
protected $template;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->id = self::$idx ++;
|
||||
$this->setUp();
|
||||
}
|
||||
|
||||
function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return self::$prefix . intval($this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ãåíåðàöèÿ êîäà èíèöèàëèçàöèè êîìïîíåíòà íà ñòîðîíå êëèåíòà
|
||||
*/
|
||||
public function getCodeBefore()
|
||||
{
|
||||
$result =
|
||||
// "alert('".$this->getName()."');" .
|
||||
"var " . $this->getName() . " = new " . get_class($this) . "("
|
||||
. json::encode($this->data) . ");";
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setData($name, $value)
|
||||
{
|
||||
$this->data[$name] = $value;
|
||||
}
|
||||
|
||||
public function getCodeAfter()
|
||||
{
|
||||
return $this->getName() . ".appendTo(document.getElementById('" . $this->getName() . "'));\n";
|
||||
}
|
||||
|
||||
public function postMake()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Ãåíåðàöèÿ êîìïîíåíòà
|
||||
*/
|
||||
function make(Controller $parent)
|
||||
{
|
||||
$this->view = $parent->getView($this->template); // Controller
|
||||
$this->view->index = $this->getName();
|
||||
foreach ($this->data as $name => $value) {
|
||||
$this->view->set($name, $value);
|
||||
}
|
||||
$this->view->addScriptRaw($this->getCodeBefore(), true);
|
||||
$this->postMake();
|
||||
$this->view->addScriptRaw($this->getCodeAfter(), true);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue