Skip to content
This repository has been archived by the owner on Mar 27, 2021. It is now read-only.

Commit

Permalink
Vytažení KT_HTML_Tag_Base->setAttrMaxlength() + úpravy do (nové) verze
Browse files Browse the repository at this point in the history
  • Loading branch information
hlavacm committed Jun 23, 2015
1 parent aed1316 commit cca4ab7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 39 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -9,5 +9,8 @@ Vytvářejte WP šablony rychle, snadno, efektivně a přehledně!
- [Dokumentace](http://www.wpframework.cz/dokumentace/)
- [O projektu](http://www.wpframework.cz/o-projektu/)

Třetí strany:

- [Magnific Popup](http://dimsemenov.com/plugins/magnific-popup/)

Copyright © [KTStudio.cz](http://www.ktstudio.cz/) 2014-2015
41 changes: 24 additions & 17 deletions core/classes/fields/kt_color_field.inc.php
@@ -1,19 +1,26 @@
<?php

/**
* GUI prvek pro výběr barvy
*
* @deprecated ve vývoji
*
* @author Tomáš Kocifaj
* @link http://www.ktstudio.cz
*/
class KT_Color_Field extends KT_Field {

const FIELD_TYPE = "color";

private $defaultColor = null;

public function __construct($name, $label) {
parent::__construct($name, $label);
$this->addAttrClass("colorField");
}



// --- gettery & settery ------------------

/**
* Vrátí nastavenou výchozí barvu
*
Expand All @@ -38,7 +45,7 @@ public function getDefaultColor() {
public function setDefaultColor($defaultColor) {
$this->defaultColor = $defaultColor;
return $this;
}
}

/**
* Vrátí typ fieldu
Expand All @@ -48,16 +55,16 @@ public function setDefaultColor($defaultColor) {
*
* @return string
*/
public function getFieldType(){
public function getFieldType() {
return self::FIELD_TYPE;
}

// --- veřejné funkce ------------------
public function renderField(){

public function renderField() {
echo $this->getField();
}

/**
* Vrátí HTML strukturu pro zobrazní fieldu
*
Expand All @@ -73,13 +80,13 @@ public function getField() {
$value = htmlentities($this->getValue());

$html .= "<input type=\"text\" ";
$html .= $this->getBasicHtml();
$html .= $this->getBasicHtml();
$html .= " value=\"{$value}\" ";
if(KT::notIssetOrEmpty($this->getDefaultColor())){

if (KT::notIssetOrEmpty($this->getDefaultColor())) {
$html .= " data-default-color=\"{$this->getDefaultColor()}\"";
}

$html .= "/>";

if ($this->hasErrorMsg()) {
Expand All @@ -88,5 +95,5 @@ public function getField() {

return $html;
}

}
55 changes: 34 additions & 21 deletions core/classes/kt_html_tag_base.inc.php
Expand Up @@ -33,9 +33,9 @@ protected function setAttributes(array $attributes = array()) {
$this->attributes = $attributes;
return $this;
}

// --- protected funkce ------------------

/**
* Připraví string se zadanými attributy
*
Expand All @@ -52,41 +52,41 @@ protected function getAttributeString() {
}

foreach ($attrCollection as $key => $value) {
if($key == self::CLASS_KEY){
if ($key == self::CLASS_KEY) {
continue;
}

if (KT::issetAndNotEmpty($value)) {
$html .= $key . "=\"" . htmlspecialchars($value) . "\" ";
} else {
$html .= $key . " ";
}
}

$html .= $this->getAttrClassString();

return $html;
}

/**
* Vrítí string se všemi CSS class zadané danému elementu.
*
* @author Tomáš Kocifaj
*
* @return string
*/
protected function getAttrClassString(){
protected function getAttrClassString() {
$html = "";
if(array_key_exists(self::CLASS_KEY, $this->getAttributes())){
if (array_key_exists(self::CLASS_KEY, $this->getAttributes())) {
$classString = "";

foreach($this->getClasses() as $class){
foreach ($this->getClasses() as $class) {
$classString .= $class . " ";
}

$html .= self::CLASS_KEY . "=\"$classString\"";
}

return $html;
}

Expand All @@ -98,7 +98,7 @@ protected function getAttrClassString(){
protected function renderAttributeString() {
echo $this->getAttributeString();
}

/**
* Vrátí hodnotu nastaveného attributu
*
Expand All @@ -107,8 +107,8 @@ protected function renderAttributeString() {
* @param string $attrName
* @return string | array
*/
protected function getAttrValueByName($attrName){
if(array_key_exists($attrName, $this->getAttributes())){
protected function getAttrValueByName($attrName) {
if (array_key_exists($attrName, $this->getAttributes())) {
return $this->attributes[$attrName];
}
}
Expand Down Expand Up @@ -170,6 +170,19 @@ public function setAttrTitle($title) {
return $this;
}

/**
* Nastaví HTML attr MAXLENGTH danému elementu
*
* @author Tomáš Kocifaj
*
* @param int $maxlength
* @return \KT_HTML_Tag_Base
*/
public function setAttrMaxlength($maxlength) {
$this->addAttribute("maxlength", $maxlength);
return $this;
}

/**
* Přidá jednu class do HTML attr CLASS danému elementu
*
Expand All @@ -180,14 +193,14 @@ public function setAttrTitle($title) {
*/
public function addAttrClass($class) {
$classes = explode(" ", $class);
if(KT::issetAndNotEmpty($classes)){

if (KT::issetAndNotEmpty($classes)) {
$currentClasses = $this->getClasses();
$newClasses = array_merge($classes, $currentClasses);
$this->setClasses($newClasses);
return $this;
}

if (array_key_exists(self::CLASS_KEY, $this->attributes)) {
array_push($this->attributes[self::CLASS_KEY], $class);
return $this;
Expand Down Expand Up @@ -221,21 +234,21 @@ public function removeAttrClass($class) {
* @return array
*/
private function getClasses() {
if(array_key_exists(self::CLASS_KEY, $this->getAttributes())){
if (array_key_exists(self::CLASS_KEY, $this->getAttributes())) {
return $this->attributes[self::CLASS_KEY];
}

return array();
}

/**
* Nastaví kolekci všech CSS tříd, které danému elementu patří.
*
* @author Tomáš Kocifaj
*
* @param array $classes
*/
private function setClasses(array $classes = array()){
private function setClasses(array $classes = array()) {
$this->attributes[self::CLASS_KEY] = $classes;
}

Expand Down
2 changes: 1 addition & 1 deletion kt_init.inc.php
Expand Up @@ -2,7 +2,7 @@

define("KT_LOADED", TRUE);

define("KT_VERSION", "1.1");
define("KT_VERSION", "1.2");

define("KT_BASE_PATH", path_join(TEMPLATEPATH, "kt"));
define("KT_BASE_URL", get_template_directory_uri() . "/kt");
Expand Down

0 comments on commit cca4ab7

Please sign in to comment.