SheetTrait.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. namespace ZN\ViewObjects;
  3. trait SheetTrait
  4. {
  5. //----------------------------------------------------------------------------------------------------
  6. //
  7. // Yazar : Ozan UYKUN <ozanbote@windowslive.com> | <ozanbote@gmail.com>
  8. // Site : www.zntr.net
  9. // Lisans : The MIT License
  10. // Telif Hakkı: Copyright (c) 2012-2016, zntr.net
  11. //
  12. //----------------------------------------------------------------------------------------------------
  13. /* Selector Değişkeni
  14. *
  15. * Seçici bilgisini tutması için
  16. * oluşturulumuştur.
  17. */
  18. private $selector = 'this';
  19. /* Attr Değişkeni
  20. *
  21. * Eklenmek istenen farklı css kodlarına.
  22. * ait bilgileri tutması için oluşturulmuştur.
  23. */
  24. protected $attr;
  25. /* Easing Değişkeni
  26. *
  27. * Easing animasyon bilgisini tutması
  28. * için oluşturulumuştur.
  29. */
  30. protected $easing;
  31. /* Transtions Değişkeni
  32. *
  33. * Geçiş efektlerine ait kullanacak
  34. * verileri tutması için oluşturulmuştur.
  35. *
  36. */
  37. protected $transitions = '';
  38. protected $tag = false;
  39. // Construct yapıcısı tarafından
  40. // Config/Css3.php dosyasından ayarlar alınıyor.
  41. public function __construct($tag = false)
  42. {
  43. $this->browsers = \Config::get('ViewObjects', 'css3')['browsers'];
  44. $this->tag = $tag;
  45. }
  46. protected function _tag($code)
  47. {
  48. if( $this->tag === true )
  49. {
  50. return \Style::open().$code.\Style::close();
  51. }
  52. return $code;
  53. }
  54. /******************************************************************************************
  55. * ATTR *
  56. *******************************************************************************************
  57. | Genel Kullanım: Farklı bir css kodu ekleneceği zaman kullanılır. |
  58. | |
  59. | Parametreler: Tek dizi parametresi vardır. |
  60. | 1. array var @_attributes => Eklenecek css kodları ve değerleri. |
  61. | |
  62. | Örnek Kullanım: ->attr(array('color' => 'red', 'border' => 'solid 1px #000')) |
  63. | |
  64. ******************************************************************************************/
  65. private function _attr($_attributes = [])
  66. {
  67. $attribute = '';
  68. if( is_array($_attributes) )
  69. {
  70. foreach($_attributes as $key => $values)
  71. {
  72. if( is_numeric($key) )
  73. {
  74. $key = $values;
  75. }
  76. $attribute .= ' '.$key.':'.$values.';';
  77. }
  78. }
  79. return $attribute;
  80. }
  81. /******************************************************************************************
  82. * ATTR *
  83. *******************************************************************************************
  84. | Genel Kullanım: Farklı bir css kodu ekleneceği zaman kullanılır. |
  85. | |
  86. | Parametreler: Tek dizi parametresi vardır. |
  87. | 1. array var @_attributes => Eklenecek css kodları ve değerleri. |
  88. | |
  89. | Örnek Kullanım: ->attr(array('color' => 'red', 'border' => 'solid 1px #000')) |
  90. | |
  91. ******************************************************************************************/
  92. public function attr($_attributes = [])
  93. {
  94. $this->attr = $this->_attr($_attributes);
  95. return $this;
  96. }
  97. /******************************************************************************************
  98. * SELECTOR *
  99. *******************************************************************************************
  100. | Genel Kullanım: Css kodlarının uygulanacağı nesne seçicisi. |
  101. | |
  102. | Parametreler: Tek parametresi vardır. |
  103. | 1. string var @selector => .nesne, #eleman, td ... gibi seçiciler belirtilir. |
  104. | |
  105. | Örnek Kullanım: ->selector('#eleman') |
  106. | |
  107. ******************************************************************************************/
  108. public function selector($selector = '')
  109. {
  110. if( ! isChar($selector) )
  111. {
  112. \Errors::set('Error', 'valueParameter', 'selector');
  113. return $this;
  114. }
  115. $this->selector = $selector;
  116. return $this;
  117. }
  118. // PRIVATE transitions nesnesi
  119. private function _transitions($data)
  120. {
  121. $transitions = "";
  122. foreach($this->browsers as $val)
  123. {
  124. $transitions .= "$val$data";
  125. }
  126. return EOL.$transitions;
  127. }
  128. /******************************************************************************************
  129. * TRANSITION COMPLETE *
  130. *******************************************************************************************
  131. | Genel Kullanım: Çoklu animasyon oluşturulacağı zaman sonlandırma yöntemi olarak |
  132. | kullanılır |
  133. | |
  134. | Örnek Kullanım: ->complete() |
  135. | |
  136. ******************************************************************************************/
  137. public function complete()
  138. {
  139. $trans = $this->transitions;
  140. $this->_defaultVariable();
  141. return $trans;
  142. }
  143. /******************************************************************************************
  144. * TRANSITION CREATE *
  145. *******************************************************************************************
  146. | Genel Kullanım: Animasyon oluşturmada kullanılan son yöntemdir. |
  147. | |
  148. | Örnek Kullanım: ->create() |
  149. | |
  150. ******************************************************************************************/
  151. public function create(...$args)
  152. {
  153. $combineTransitions = $args;
  154. $str = $this->selector."{";
  155. if( ! empty($this->attr) ) $str .= EOL.$this->attr.EOL;
  156. $str .= $this->complete();
  157. if( ! empty($combineTransitions) ) foreach( $combineTransitions as $transition )
  158. {
  159. $str .= $transition;
  160. }
  161. $str .= "}".EOL;
  162. return $this->_tag($str);
  163. }
  164. // Değişkenler default ayarlarına getiriliyor.
  165. protected function _defaultVariable()
  166. {
  167. if( ! empty($this->attr) ) $this->attr = NULL;
  168. if( ! empty($this->transitions) ) $this->transitions = '';
  169. if( $this->selector !== 'this' ) $this->selector = 'this';
  170. }
  171. }