FoundationRichTextareaElement.class.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. class Staple_Form_FoundationRichTextareaElement extends Staple_Form_Element
  3. {
  4. /**
  5. * Size of the text field.
  6. * @var int
  7. */
  8. protected $size;
  9. /**
  10. * Maxlength of the textfield.
  11. * @var int
  12. */
  13. protected $max;
  14. /**
  15. * @return the $size
  16. */
  17. public function getSize()
  18. {
  19. return $this->size;
  20. }
  21. /**
  22. * @return the $max
  23. */
  24. public function getMax()
  25. {
  26. return $this->max;
  27. }
  28. /**
  29. * @param int $size
  30. */
  31. public function setSize($size)
  32. {
  33. $this->size = (int)$size;
  34. return $this;
  35. }
  36. /**
  37. * @param int $max
  38. */
  39. public function setMax($max)
  40. {
  41. $this->max = (int)$max;
  42. return $this;
  43. }
  44. /**
  45. * Build the field label.
  46. * @see Staple_Form_Element::label()
  47. * @return string
  48. */
  49. public function label()
  50. {
  51. if(count($this->errors) != 0)
  52. {
  53. $buf = "<label for=\"".$this->escape($this->id)."\" class=\"error\">";
  54. }
  55. else
  56. {
  57. $buf = "<label for=\"".$this->escape($this->id)."\">";
  58. }
  59. if($this->required == 1)
  60. {
  61. $buf .= "<b>";
  62. $buf .= $this->label;
  63. $buf .= "</b> <small>(<i>Required</i>)</small>";
  64. }
  65. else
  66. {
  67. $buf .= $this->label;
  68. }
  69. $buf .= "</label>\n";
  70. return $buf;
  71. }
  72. /**
  73. * Build the field itself.
  74. * @see Staple_Form_Element::field()
  75. * @return string
  76. */
  77. public function field()
  78. {
  79. $classes = $this->getClassString();
  80. return ' <textarea style="display:none;" id="'.$this->escape($this->id).'" name="'.$this->escape($this->name).'" '.$this->getAttribString().' '.$classes.' >'.$this->escape($this->value).'</textarea>'."\n";
  81. }
  82. /**
  83. * Build the form field.
  84. * @see Staple_Form_Element::build()
  85. * @return string
  86. */
  87. public function build()
  88. {
  89. $buf = '';
  90. $view = FORMS_ROOT.'/fields/FoundationRichTextareaElement.phtml';
  91. if(file_exists($view))
  92. {
  93. ob_start();
  94. include $view;
  95. $buf = ob_get_contents();
  96. ob_end_clean();
  97. }
  98. else
  99. {
  100. $classes = $this->getClassString();
  101. $buf .= "<div class=\"row\">\n"; //Row Start
  102. $buf .= "<div class=\"small-12 columns\">\n"; //Label Start
  103. $buf .= $this->label();
  104. $buf .= "</div>\n"; //Label End
  105. $buf .= "<div class=\"small-12 columns\">\n"; //Field Start
  106. if(count($this->errors) != 0)
  107. {
  108. $buf .= "<label class=\"error\">";
  109. }
  110. $buf .= $this->field();
  111. $buf .= "
  112. <ul class=\"button-group\" style=\"padding:0; margin:0;\">
  113. <li>
  114. <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Bold\">
  115. <a href=\"#\" id=\"iBold\" class=\"button secondary small\"><i class=\"fi-bold\"></i></a>
  116. </span>
  117. </li>
  118. <li>
  119. <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Italic\">
  120. <a href=\"#\" id=\"iItalic\" class=\"button secondary small\"><i class=\"fi-italic\"></i></a>
  121. </span>
  122. </li>
  123. <li>
  124. <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Underline\">
  125. <a href=\"#\" id=\"iUnderline\" class=\"button secondary small\"><i class=\"fi-underline\"></i></a>
  126. </span>
  127. </li>
  128. <li>
  129. <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Font Color\">
  130. <a href=\"#\" id=\"iColor\" class=\"button secondary small\"><i class=\"fi-text-color\" style=\"color:red;\"></i></a>
  131. </span>
  132. </li>
  133. <li>
  134. <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Font Size\">
  135. <a href=\"#\" id=\"iSize\" class=\"button secondary small\">+/-</a>
  136. </span>
  137. </li>
  138. <li>
  139. <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Ordered List\">
  140. <a href=\"#\" id=\"iOList\" class=\"button secondary small\"><i class=\"fi-list-thumbnails\"></i></a>
  141. </span>
  142. </li>
  143. <li>
  144. <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Unordered List\">
  145. <a href=\"#\" id=\"iUList\" class=\"button secondary small\"><i class=\"fi-list\"></i></a>
  146. </span>
  147. </li>
  148. <li>
  149. <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"More Indent\">
  150. <a href=\"#\" id=\"iIndent\" class=\"button secondary small\"><i class=\"fi-indent-more\"></i></a>
  151. </span>
  152. </li>
  153. <li>
  154. <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Less Indent\">
  155. <a href=\"#\" id=\"iOutdent\" class=\"button secondary small\"><i class=\"fi-indent-less\"></i></a>
  156. </span>
  157. </li>
  158. <li>
  159. <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Justify Center\">
  160. <a href=\"#\" id=\"iJCenter\" class=\"button secondary small\"><i class=\"fi-align-center\"></i></a>
  161. </span>
  162. </li>
  163. <li>
  164. <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Justify Left\">
  165. <a href=\"#\" id=\"iJLeft\" class=\"button secondary small\"><i class=\"fi-align-left\"></i></a>
  166. </span>
  167. </li>
  168. <li>
  169. <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Justify Right\">
  170. <a href=\"#\" id=\"iJRight\" class=\"button secondary small\"><i class=\"fi-align-right\"></i></a>
  171. </span>
  172. </li>
  173. <li>
  174. <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Insert Image\">
  175. <a href=\"#\" id=\"iImage\" class=\"button secondary small\"><i class=\"fi-photo\"></i></a>
  176. </span>
  177. </li>
  178. <li>
  179. <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Clear Formating\">
  180. <a href=\"#\" id=\"clearFormatting\" class=\"button secondary small\"><i class=\"fi-x\"></i></a>
  181. </span>
  182. </li>
  183. </ul>
  184. ";
  185. $buf .= "<textarea name=\"i".$this->getId()."\" id=\"i".$this->getId()."\" ".$classes." style=\"width:100%; border:1px #ccc solid; min-height:250px;\"></textarea>";
  186. $buf .= "<script>
  187. $(document).ready(function()
  188. {
  189. i".$this->getId().".document.designMode = 'On';
  190. $('#iBold').click(function() {
  191. i".$this->getId().".document.execCommand('bold',false,null);
  192. return false;
  193. });
  194. $('#iItalic').click(function() {
  195. i".$this->getId().".document.execCommand('italic',false,null);
  196. return false;
  197. });
  198. $('#iUnderline').click(function() {
  199. i".$this->getId().".document.execCommand('underline',false,null);
  200. return false;
  201. });
  202. $('#iColor').click(function() {
  203. var color = prompt('Define a basic color or apply a hexadecimal color:','');
  204. i".$this->getId().".document.execCommand('ForeColor',false,color);
  205. return false;
  206. });
  207. $('#iOList').click(function() {
  208. i".$this->getId().".document.execCommand('InsertOrderedList',false,'newOL');
  209. return false;
  210. });
  211. $('#iUList').click(function() {
  212. i".$this->getId().".document.execCommand('InsertUnorderedList',false,'newUL');
  213. return false;
  214. });
  215. $('#iIndent').click(function() {
  216. i".$this->getId().".document.execCommand('indent',false,'');
  217. return false;
  218. });
  219. $('#iOutdent').click(function() {
  220. i".$this->getId().".document.execCommand('outdent',false,'');
  221. return false;
  222. });
  223. $('#iSize').click(function() {
  224. var size = prompt('Define a font size from 1 to 7:','');
  225. i".$this->getId().".document.execCommand('FontSize',false,size);
  226. return false;
  227. });
  228. $('#iLink').click(function() {
  229. var url = prompt('Enter the URL:','http://');
  230. i".$this->getId().".document.execCommand('CreateLink',false,url);
  231. return false;
  232. });
  233. $('#iJCenter').click(function() {
  234. i".$this->getId().".document.execCommand('justifyCenter',false,'');
  235. return false;
  236. });
  237. $('#iJRight').click(function() {
  238. i".$this->getId().".document.execCommand('justifyRight',false,'');
  239. return false;
  240. });
  241. $('#iJLeft').click(function() {
  242. i".$this->getId().".document.execCommand('justifyLeft',false,'');
  243. return false;
  244. });
  245. $('#iImage').click(function() {
  246. var url = prompt('Enter the URL from the image:','http://');
  247. i".$this->getId().".document.execCommand('insertImage',false,url);
  248. return false;
  249. });
  250. $('#clearFormatting').click(function() {
  251. i".$this->getId().".document.execCommand('removeFormat',false,'');
  252. return false;
  253. });
  254. $('#submit').click(function() {
  255. });
  256. });
  257. </script>
  258. ";
  259. if(count($this->errors) != 0)
  260. {
  261. $buf .= "</label>";
  262. $buf .= "<small class=\"error\">";
  263. foreach($this->errors as $error)
  264. {
  265. foreach($error as $message)
  266. {
  267. $buf .= "- $message<br>\n";
  268. }
  269. }
  270. $buf .= "</small>";
  271. }
  272. $buf .= "</div>\n"; //Field End
  273. $buf .= "</div>\n"; //Row end
  274. }
  275. return $buf;
  276. }
  277. }