Advertisement
belostotsky

add search with placeholder to bootique73

Nov 14th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. <?php
  2. /**
  3. * @package Make
  4. */
  5. ?>
  6.  
  7. <script>
  8. /* based on http://github.com/NV/placeholder.js/ */
  9. function inputPlaceholder (input, placeholder, color) {
  10.  
  11. if (!input) return null;
  12.  
  13. var placeholder_color = color || '#AAA';
  14. var default_color = input.style.color;
  15.  
  16. if (input.value === '' || input.value == placeholder) {
  17. input.value = placeholder;
  18. input.style.color = placeholder_color;
  19. }
  20.  
  21. var add_event = /*@cc_on'attachEvent'||@*/'addEventListener';
  22.  
  23. input[add_event](/*@cc_on'on'+@*/'focus', function(){
  24. input.style.color = default_color;
  25. if (input.value == placeholder) {
  26. input.value = '';
  27. }
  28. }, false);
  29.  
  30. input[add_event](/*@cc_on'on'+@*/'blur', function(){
  31. if (input.value === '') {
  32. input.value = placeholder;
  33. input.style.color = placeholder_color;
  34. } else {
  35. input.style.color = default_color;
  36. }
  37. }, false);
  38.  
  39. input.form && input.form[add_event](/*@cc_on'on'+@*/'submit', function(){
  40. if (input.value == placeholder) {
  41. input.value = '';
  42. }
  43. }, false);
  44.  
  45. return input;
  46. }
  47.  
  48. function getElementsByClassName(classname, node) {
  49. if(!node) node = document.getElementsByTagName("body")[0];
  50. var a = [];
  51. var re = new RegExp('\\b' + classname + '\\b');
  52. var els = node.getElementsByTagName("*");
  53. for(var i=0,j=els.length; i<j; i++)
  54. if(re.test(els[i].className))a.push(els[i]);
  55. return a;
  56. }
  57.  
  58.  
  59. function ecwid_set_placeholder() {
  60. var search_box = getElementsByClassName('ecwid-SearchPanel-field')[0];
  61. if (search_box) {
  62. inputPlaceholder(search_box,'Поиск');
  63. clearInterval(ecwid_set_placeholder_interval);
  64. }
  65. }
  66. var ecwid_set_placeholder_interval;
  67. ecwid_set_placeholder_interval = setInterval('ecwid_set_placeholder();',100);
  68. </script>
  69.  
  70. <div class="search-form">
  71. <div calss="search-field">
  72. <script type="text/javascript" src="http://app.ecwid.com/script.js?4120544" charset="utf-8"></script>
  73. <script type="text/javascript"> xSearchPanel("id=my-search-4120544"); </script>
  74. </div>
  75. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement