PageRenderTime 22ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/core/Mage/Core/Helper/Js.php

https://github.com/gryzz/crystal_magento
PHP | 202 lines | 108 code | 13 blank | 81 comment | 3 complexity | 5dd17ea94c64cdc0a857f2f2c6210907 MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Core
  23. * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * JavaScript helper
  28. *
  29. * @author Magento Core Team <core@magentocommerce.com>
  30. */
  31. class Mage_Core_Helper_Js extends Mage_Core_Helper_Abstract
  32. {
  33. /**
  34. * Array of senteces of JS translations
  35. *
  36. * @var array
  37. */
  38. protected $_translateData = null;
  39. /**
  40. * Retrieve JSON of JS sentences translation
  41. *
  42. * @return string
  43. */
  44. public function getTranslateJson()
  45. {
  46. return Mage::helper('core')->jsonEncode($this->_getTranslateData());
  47. }
  48. /**
  49. * Retrieve JS translator initialization javascript
  50. *
  51. * @return string
  52. */
  53. public function getTranslatorScript()
  54. {
  55. $script = 'var Translator = new Translate('.$this->getTranslateJson().');';
  56. return $this->getScript($script);
  57. }
  58. /**
  59. * Retrieve framed javascript
  60. *
  61. * @param string $script
  62. * @return script
  63. */
  64. public function getScript($script)
  65. {
  66. return '<script type="text/javascript">'.$script.'</script>';
  67. }
  68. /**
  69. * Retrieve javascript include code
  70. *
  71. * @param string $file
  72. * @return string
  73. */
  74. public function includeScript($file)
  75. {
  76. return '<script type="text/javascript" src="'.$this->getJsUrl($file).'"></script>'."\n";
  77. }
  78. /**
  79. * Retrieve
  80. *
  81. * @param string $file
  82. * @return string
  83. */
  84. public function includeSkinScript($file)
  85. {
  86. return '<script type="text/javascript" src="'.$this->getJsSkinUrl($file).'"></script>';
  87. }
  88. /**
  89. * Retrieve JS file url
  90. *
  91. * @param string $file
  92. * @return string
  93. */
  94. public function getJsUrl($file)
  95. {
  96. return Mage::getBaseUrl('js').$file;
  97. }
  98. /**
  99. * Retrieve skin JS file url
  100. *
  101. * @param string $file
  102. * @return string
  103. */
  104. public function getJsSkinUrl($file)
  105. {
  106. return Mage::getDesign()->getSkinUrl($file, array());
  107. }
  108. /**
  109. * Retrieve JS translation array
  110. *
  111. * @return array
  112. */
  113. protected function _getTranslateData()
  114. {
  115. if ($this->_translateData ===null) {
  116. $this->_translateData = array(
  117. 'Please select an option.' => $this->__('Please select an option.'),
  118. 'This is a required field.' => $this->__('This is a required field.'),
  119. 'Please enter a valid number in this field.' => $this->__('Please enter a valid number in this field.'),
  120. 'Please use numbers only in this field. please avoid spaces or other characters such as dots or commas.' =>
  121. $this->__('Please use numbers only in this field. please avoid spaces or other characters such as dots or commas.'),
  122. 'Please use letters only (a-z) in this field.' => $this->__('Please use letters only (a-z) in this field.'),
  123. 'Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first character should be a letter.' =>
  124. $this->__('Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first character should be a letter.'),
  125. 'Please use only letters (a-z) or numbers (0-9) only in this field. No spaces or other characters are allowed.' =>
  126. $this->__('Please use only letters (a-z) or numbers (0-9) only in this field. No spaces or other characters are allowed.'),
  127. 'Please use only letters (a-z) or numbers (0-9) or spaces and # only in this field.' =>
  128. $this->__('Please use only letters (a-z) or numbers (0-9) or spaces and # only in this field.'),
  129. 'Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.' =>
  130. $this->__('Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.'),
  131. 'Please enter a valid date.' => $this->__('Please enter a valid date.'),
  132. 'Please enter a valid email address. For example johndoe@domain.com.' =>
  133. $this->__('Please enter a valid email address. For example johndoe@domain.com.'),
  134. 'Please enter 6 or more characters.' => $this->__('Please enter 6 or more characters.'),
  135. 'Please make sure your passwords match.' => $this->__('Please make sure your passwords match.'),
  136. 'Please enter a valid URL. http:// is required' => $this->__('Please enter a valid URL. http:// is required'),
  137. 'Please enter a valid URL. For example http://www.example.com or www.example.com' =>
  138. $this->__('Please enter a valid URL. For example http://www.example.com or www.example.com'),
  139. 'Please enter a valid social security number. For example 123-45-6789.' =>
  140. $this->__('Please enter a valid social security number. For example 123-45-6789.'),
  141. 'Please enter a valid zip code. For example 90602 or 90602-1234.' =>
  142. $this->__('Please enter a valid zip code. For example 90602 or 90602-1234.'),
  143. 'Please enter a valid zip code.' => $this->__('Please enter a valid zip code.'),
  144. 'Please use this date format: dd/mm/yyyy. For example 17/03/2006 for the 17th of March, 2006.' =>
  145. $this->__('Please use this date format: dd/mm/yyyy. For example 17/03/2006 for the 17th of March, 2006.'),
  146. 'Please enter a valid $ amount. For example $100.00.' =>
  147. $this->__('Please enter a valid $ amount. For example $100.00.'),
  148. 'Please select one of the above options.' => $this->__('Please select one of the above options.'),
  149. 'Please select one of the options.' => $this->__('Please select one of the options.'),
  150. 'Please enter a valid number in this field.' => $this->__('Please enter a valid number in this field.'),
  151. 'Please select State/Province.' => $this->__('Please select State/Province.'),
  152. 'Please enter valid password.' => $this->__('Please enter valid password.'),
  153. 'Please enter 6 or more characters. Leading or trailing spaces will be ignored.' =>
  154. $this->__('Please enter 6 or more characters. Leading or trailing spaces will be ignored.'),
  155. 'Please use letters only (a-z or A-Z) in this field.' => $this->__('Please use letters only (a-z or A-Z) in this field.'),
  156. 'Please enter a number greater than 0 in this field.' =>
  157. $this->__('Please enter a number greater than 0 in this field.'),
  158. 'Please enter a valid credit card number.' => $this->__('Please enter a valid credit card number.'),
  159. 'Please wait, loading...' => $this->__('Please wait, loading...'),
  160. 'Please choose to register or to checkout as a guest' => $this->__('Please choose to register or to checkout as a guest'),
  161. 'Error: Passwords do not match' => $this->__('Error: Passwords do not match'),
  162. 'Your order cannot be completed at this time as there is no shipping methods available for it. Please make necessary changes in your shipping address.' =>
  163. $this->__('Your order cannot be completed at this time as there is no shipping methods available for it. Please make necessary changes in your shipping address.'),
  164. 'Please specify shipping method.' => $this->__('Please specify shipping method.'),
  165. 'Your order cannot be completed at this time as there is no payment methods available for it.' =>
  166. $this->__('Your order cannot be completed at this time as there is no payment methods available for it.'),
  167. 'Please specify payment method.' => $this->__('Please specify payment method.'),
  168. 'Credit card number doesn\'t match credit card type' => $this->__('Credit card number does not match credit card type'),
  169. 'Card type does not match credit card number' => $this->__('Card type does not match credit card number'),
  170. 'Please enter a valid credit card verification number.' => $this->__('Please enter a valid credit card verification number.'),
  171. 'Please use only letters (a-z or A-Z), numbers (0-9) or underscore(_) in this field, first character should be a letter.' =>
  172. $this->__('Please use only letters (a-z or A-Z), numbers (0-9) or underscores (_) in this field, first character must be a letter.'),
  173. 'Please input a valid CSS-length. For example 100px or 77pt or 20em or .5ex or 50%' => $this->__('Please input a valid CSS-length. For example 100px or 77pt or 20em or .5ex or 50%'),
  174. 'Maximum length exceeded.' => $this->__('Maximum length exceeded.'),
  175. //Mage_Rule
  176. 'Your session has been expired, you will be relogged in now.' => $this->__('Your session has been expired, you will be relogged in now.'),
  177. 'Incorrect credit card expiration date' => $this->__('Incorrect credit card expiration date'),
  178. // Date
  179. 'This date is a required value.' => $this->__('This date is a required value.'),
  180. );
  181. foreach ($this->_translateData as $key=>$value) {
  182. if ($key == $value) {
  183. unset($this->_translateData[$key]);
  184. }
  185. }
  186. }
  187. return $this->_translateData;
  188. }
  189. }