Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

520 Zeilen
14 KiB

  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. function setLocation(url) {
  6. window.location.href = url;
  7. }
  8. function setElementDisable(element, disable) {
  9. if ($(element)) {
  10. $(element).disabled = disable;
  11. }
  12. }
  13. function toggleParentVis(obj) {
  14. obj = $(obj).parentNode;
  15. if (obj.style.display == 'none') {
  16. obj.style.display = '';
  17. } else {
  18. obj.style.display = 'none';
  19. }
  20. }
  21. // to fix new app/design/adminhtml/default/default/template/widget/form/renderer/fieldset.phtml
  22. // with toggleParentVis
  23. function toggleFieldsetVis(obj) {
  24. id = obj;
  25. obj = $(obj);
  26. if (obj.style.display == 'none') {
  27. obj.style.display = '';
  28. } else {
  29. obj.style.display = 'none';
  30. }
  31. obj = obj.parentNode.childElements();
  32. for (var i = 0; i < obj.length; i++) {
  33. if (obj[i].id != undefined &&
  34. obj[i].id == id &&
  35. obj[i - 1].classNames() == 'entry-edit-head') {
  36. if (obj[i - 1].style.display == 'none') {
  37. obj[i - 1].style.display = '';
  38. } else {
  39. obj[i - 1].style.display = 'none';
  40. }
  41. }
  42. }
  43. }
  44. function toggleVis(obj) {
  45. obj = $(obj);
  46. if (obj.style.display == 'none') {
  47. obj.style.display = '';
  48. } else {
  49. obj.style.display = 'none';
  50. }
  51. }
  52. function imagePreview(element) {
  53. if ($(element)) {
  54. var win = window.open('', 'preview', 'width=400,height=400,resizable=1,scrollbars=1');
  55. win.document.open();
  56. win.document.write('<body style="padding:0;margin:0"><img src="' + $(element).src + '" id="image_preview"/></body>');
  57. win.document.close();
  58. Event.observe(win, 'load', function () {
  59. var img = win.document.getElementById('image_preview');
  60. win.resizeTo(img.width + 40, img.height + 80);
  61. });
  62. }
  63. }
  64. function checkByProductPriceType(elem) {
  65. if (elem.id == 'price_type') {
  66. this.productPriceType = elem.value;
  67. return false;
  68. }
  69. if (elem.id == 'price' && this.productPriceType == 0) {
  70. return false;
  71. }
  72. return true;
  73. }
  74. function toggleSeveralValueElements(checkbox, containers, excludedElements, checked) {
  75. 'use strict';
  76. if (containers && checkbox) {
  77. if (Object.prototype.toString.call(containers) != '[object Array]') {
  78. containers = [containers];
  79. }
  80. containers.each(function (container) {
  81. toggleValueElements(checkbox, container, excludedElements, checked);
  82. });
  83. }
  84. }
  85. function toggleValueElements(checkbox, container, excludedElements, checked) {
  86. if (container && checkbox) {
  87. var ignoredElements = [checkbox];
  88. if (typeof excludedElements != 'undefined') {
  89. if (Object.prototype.toString.call(excludedElements) != '[object Array]') {
  90. excludedElements = [excludedElements];
  91. }
  92. for (var i = 0; i < excludedElements.length; i++) {
  93. ignoredElements.push(excludedElements[i]);
  94. }
  95. }
  96. //var elems = container.select('select', 'input');
  97. var elems = Element.select(container, ['select', 'input', 'textarea', 'button', 'img']).filter(function (el) {
  98. return el.readAttribute('type') != 'hidden';
  99. });
  100. var isDisabled = checked != undefined ? checked : checkbox.checked;
  101. elems.each(function (elem) {
  102. if (checkByProductPriceType(elem)) {
  103. var i = ignoredElements.length;
  104. while (i-- && elem != ignoredElements[i]);
  105. if (i != -1) {
  106. return;
  107. }
  108. elem.disabled = isDisabled;
  109. if (isDisabled) {
  110. elem.addClassName('disabled');
  111. } else {
  112. elem.removeClassName('disabled');
  113. }
  114. if (elem.nodeName.toLowerCase() == 'img') {
  115. isDisabled ? elem.hide() : elem.show();
  116. }
  117. }
  118. });
  119. }
  120. }
  121. /**
  122. * @todo add validation for fields
  123. */
  124. function submitAndReloadArea(area, url) {
  125. if ($(area)) {
  126. var fields = $(area).select('input', 'select', 'textarea');
  127. var data = Form.serializeElements(fields, true);
  128. url += url.match(new RegExp('\\?')) ? '&isAjax=true' : '?isAjax=true';
  129. new Ajax.Request(url, {
  130. parameters: $H(data),
  131. loaderArea: area,
  132. onSuccess: function (transport) {
  133. try {
  134. if (transport.responseText.isJSON()) {
  135. var response = transport.responseText.evalJSON();
  136. if (response.error) {
  137. alert(response.message);
  138. }
  139. if (response.ajaxExpired && response.ajaxRedirect) {
  140. setLocation(response.ajaxRedirect);
  141. }
  142. } else {
  143. $(area).update(transport.responseText);
  144. }
  145. }
  146. catch (e) {
  147. $(area).update(transport.responseText);
  148. }
  149. }
  150. });
  151. }
  152. }
  153. /********** MESSAGES ***********/
  154. function syncOnchangeValue(baseElem, distElem) {
  155. var compare = {
  156. baseElem: baseElem, distElem: distElem
  157. };
  158. Event.observe(baseElem, 'change', function () {
  159. if ($(this.baseElem) && $(this.distElem)) {
  160. $(this.distElem).value = $(this.baseElem).value;
  161. }
  162. }.bind(compare));
  163. }
  164. // Insert some content to the cursor position of input element
  165. function updateElementAtCursor(el, value, win) {
  166. if (win == undefined) {
  167. win = window.self;
  168. }
  169. if (document.selection) {
  170. el.focus();
  171. sel = win.document.selection.createRange();
  172. sel.text = value;
  173. } else if (el.selectionStart || el.selectionStart == '0') {
  174. var startPos = el.selectionStart;
  175. var endPos = el.selectionEnd;
  176. el.value = el.value.substring(0, startPos) + value + el.value.substring(endPos, el.value.length);
  177. } else {
  178. el.value += value;
  179. }
  180. }
  181. // Firebug detection
  182. function firebugEnabled() {
  183. if (window.console && window.console.firebug) {
  184. return true;
  185. }
  186. return false;
  187. }
  188. function disableElement(elem) {
  189. elem.disabled = true;
  190. elem.addClassName('disabled');
  191. }
  192. function enableElement(elem) {
  193. elem.disabled = false;
  194. elem.removeClassName('disabled');
  195. }
  196. function disableElements(search) {
  197. $$('.' + search).each(disableElement);
  198. }
  199. function enableElements(search) {
  200. $$('.' + search).each(enableElement);
  201. }
  202. /** Cookie Reading And Writing **/
  203. var Cookie = {
  204. all: function () {
  205. var pairs = document.cookie.split(';');
  206. var cookies = {};
  207. pairs.each(function (item, index) {
  208. var pair = item.strip().split('=');
  209. cookies[unescape(pair[0])] = unescape(pair[1]);
  210. });
  211. return cookies;
  212. },
  213. read: function (cookieName) {
  214. var cookies = this.all();
  215. if (cookies[cookieName]) {
  216. return cookies[cookieName];
  217. }
  218. return null;
  219. },
  220. write: function (cookieName, cookieValue, cookieLifeTime, samesite) {
  221. var expires = '';
  222. if (cookieLifeTime) {
  223. var date = new Date();
  224. date.setTime(date.getTime() + cookieLifeTime * 1000);
  225. expires = '; expires=' + date.toUTCString();
  226. }
  227. var urlPath = '/' + BASE_URL.split('/').slice(3).join('/'); // Get relative path
  228. samesite = '; samesite=' + (samesite ? samesite : 'lax');
  229. document.cookie = escape(cookieName) + '=' + escape(cookieValue) + expires + '; path=' + urlPath + samesite;
  230. },
  231. clear: function (cookieName) {
  232. this.write(cookieName, '', -1);
  233. }
  234. };
  235. var Fieldset = {
  236. cookiePrefix: 'fh-',
  237. applyCollapse: function (containerId) {
  238. if ($(containerId + '-state')) {
  239. collapsed = $(containerId + '-state').value == 1 ? 0 : 1;
  240. } else {
  241. collapsed = $(containerId + '-head').collapsed;
  242. }
  243. if (collapsed == 1 || collapsed === undefined) {
  244. $(containerId + '-head').removeClassName('open');
  245. if ($(containerId + '-head').up('.section-config')) {
  246. $(containerId + '-head').up('.section-config').removeClassName('active');
  247. }
  248. $(containerId).hide();
  249. } else {
  250. $(containerId + '-head').addClassName('open');
  251. if ($(containerId + '-head').up('.section-config')) {
  252. $(containerId + '-head').up('.section-config').addClassName('active');
  253. }
  254. $(containerId).show();
  255. }
  256. },
  257. toggleCollapse: function (containerId, saveThroughAjax) {
  258. if ($(containerId + '-state')) {
  259. collapsed = $(containerId + '-state').value == 1 ? 0 : 1;
  260. } else {
  261. collapsed = $(containerId + '-head').collapsed;
  262. }
  263. //Cookie.read(this.cookiePrefix + containerId);
  264. if (collapsed == 1 || collapsed === undefined) {
  265. //Cookie.write(this.cookiePrefix + containerId, 0, 30*24*60*60);
  266. if ($(containerId + '-state')) {
  267. $(containerId + '-state').value = 1;
  268. }
  269. $(containerId + '-head').collapsed = 0;
  270. } else {
  271. //Cookie.clear(this.cookiePrefix + containerId);
  272. if ($(containerId + '-state')) {
  273. $(containerId + '-state').value = 0;
  274. }
  275. $(containerId + '-head').collapsed = 1;
  276. }
  277. this.applyCollapse(containerId);
  278. if (typeof saveThroughAjax != 'undefined') {
  279. this.saveState(saveThroughAjax, {
  280. container: containerId, value: $(containerId + '-state').value
  281. });
  282. }
  283. },
  284. addToPrefix: function (value) {
  285. this.cookiePrefix += value + '-';
  286. },
  287. saveState: function (url, parameters) {
  288. new Ajax.Request(url, {
  289. method: 'post',
  290. parameters: Object.toQueryString(parameters),
  291. loaderArea: false
  292. });
  293. }
  294. };
  295. var Base64 = {
  296. // private property
  297. _keyStr: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
  298. //'+/=', '-_,'
  299. // public method for encoding
  300. encode: function (input) {
  301. var output = '';
  302. var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  303. var i = 0;
  304. input = Base64._utf8_encode(input);
  305. if (typeof window.btoa === 'function') {
  306. return window.btoa(input);
  307. }
  308. while (i < input.length) {
  309. chr1 = input.charCodeAt(i++);
  310. chr2 = input.charCodeAt(i++);
  311. chr3 = input.charCodeAt(i++);
  312. enc1 = chr1 >> 2;
  313. enc2 = (chr1 & 3) << 4 | chr2 >> 4;
  314. enc3 = (chr2 & 15) << 2 | chr3 >> 6;
  315. enc4 = chr3 & 63;
  316. if (isNaN(chr2)) {
  317. enc3 = enc4 = 64;
  318. } else if (isNaN(chr3)) {
  319. enc4 = 64;
  320. }
  321. output = output +
  322. this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
  323. this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
  324. }
  325. return output;
  326. },
  327. // public method for decoding
  328. decode: function (input) {
  329. var output = '';
  330. var chr1, chr2, chr3;
  331. var enc1, enc2, enc3, enc4;
  332. var i = 0;
  333. if (typeof window.atob === 'function') {
  334. return Base64._utf8_decode(window.atob(input));
  335. }
  336. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
  337. while (i < input.length) {
  338. enc1 = this._keyStr.indexOf(input.charAt(i++));
  339. enc2 = this._keyStr.indexOf(input.charAt(i++));
  340. enc3 = this._keyStr.indexOf(input.charAt(i++));
  341. enc4 = this._keyStr.indexOf(input.charAt(i++));
  342. chr1 = enc1 << 2 | enc2 >> 4;
  343. chr2 = (enc2 & 15) << 4 | enc3 >> 2;
  344. chr3 = (enc3 & 3) << 6 | enc4;
  345. output += String.fromCharCode(chr1);
  346. if (enc3 != 64) {
  347. output += String.fromCharCode(chr2);
  348. }
  349. if (enc4 != 64) {
  350. output += String.fromCharCode(chr3);
  351. }
  352. }
  353. return Base64._utf8_decode(output);
  354. },
  355. mageEncode: function (input) {
  356. return this.encode(input).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ',');
  357. },
  358. mageDecode: function (output) {
  359. output = output.replace(/\-/g, '+').replace(/_/g, '/').replace(/,/g, '=');
  360. return this.decode(output);
  361. },
  362. idEncode: function (input) {
  363. return this.encode(input).replace(/\+/g, ':').replace(/\//g, '_').replace(/=/g, '-');
  364. },
  365. idDecode: function (output) {
  366. output = output.replace(/\-/g, '=').replace(/_/g, '/').replace(/\:/g, '\+');
  367. return this.decode(output);
  368. },
  369. // private method for UTF-8 encoding
  370. _utf8_encode: function (string) {
  371. string = string.replace(/\r\n/g, '\n');
  372. var utftext = '';
  373. for (var n = 0; n < string.length; n++) {
  374. var c = string.charCodeAt(n);
  375. if (c < 128) {
  376. utftext += String.fromCharCode(c);
  377. } else if (c > 127 && c < 2048) {
  378. utftext += String.fromCharCode(c >> 6 | 192);
  379. utftext += String.fromCharCode(c & 63 | 128);
  380. } else {
  381. utftext += String.fromCharCode(c >> 12 | 224);
  382. utftext += String.fromCharCode(c >> 6 & 63 | 128);
  383. utftext += String.fromCharCode(c & 63 | 128);
  384. }
  385. }
  386. return utftext;
  387. },
  388. // private method for UTF-8 decoding
  389. _utf8_decode: function (utftext) {
  390. var string = '';
  391. var i = 0;
  392. var c = c1 = c2 = 0;
  393. while (i < utftext.length) {
  394. c = utftext.charCodeAt(i);
  395. if (c < 128) {
  396. string += String.fromCharCode(c);
  397. i++;
  398. } else if (c > 191 && c < 224) {
  399. c2 = utftext.charCodeAt(i + 1);
  400. string += String.fromCharCode((c & 31) << 6 | c2 & 63);
  401. i += 2;
  402. } else {
  403. c2 = utftext.charCodeAt(i + 1);
  404. c3 = utftext.charCodeAt(i + 2);
  405. string += String.fromCharCode((c & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
  406. i += 3;
  407. }
  408. }
  409. return string;
  410. }
  411. };
  412. /**
  413. * Array functions
  414. */
  415. /**
  416. * Callback function for sort numeric values
  417. *
  418. * @param val1
  419. * @param val2
  420. */
  421. function sortNumeric(val1, val2) {
  422. return val1 - val2;
  423. }