Commit d79d2488bdab17b05800d4f06acfdcf5de8aa6b2

Authored by Antoine Goutenoir
1 parent 91751451
Exists in master

Work around iPad's limitations.

Showing 1 changed file with 47 additions and 0 deletions   Show diff stats
flaskr/templates/estimate.html
... ... @@ -100,3 +100,50 @@
100 100 <div class="col-md-2"></div>
101 101 </div>
102 102 {% endblock %}
  103 +
  104 +{% block js %}
  105 +<script type="text/javascript">
  106 +
  107 +// Multiline placeholders for textarea shim (eg: iPad)
  108 +// https://github.com/EmilMoe/multiline-placeholder
  109 +$(function() {
  110 + var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
  111 +
  112 + // Disable for chrome which already supports multiline
  113 + if (! ((!!window.chrome) && !isOpera)) {
  114 + var style = $('<style>textarea[data-placeholder].active { color: #666; }</style>')
  115 + $('html > head').append(style);
  116 +
  117 + $('textarea[placeholder]').each(function(index) {
  118 + var text = $(this).attr('placeholder');
  119 + var match = /\r|\n/.exec(text);
  120 +
  121 + if (! match)
  122 + return;
  123 +
  124 + $(this).attr('placeholder', '');
  125 + $(this).attr('data-placeholder', text);
  126 + $(this).addClass('active');
  127 + $(this).val(text);
  128 + });
  129 +
  130 + $('textarea[data-placeholder]').on('focus', function() {
  131 + if ($(this).attr('data-placeholder') === $(this).val()) {
  132 + $(this).attr('data-placeholder', $(this).val());
  133 + $(this).val('');
  134 + $(this).removeClass('active');
  135 + }
  136 + });
  137 +
  138 + $('textarea[data-placeholder]').on('blur', function() {
  139 + if ($(this).val() === '') {
  140 + var text = $(this).attr('data-placeholder');
  141 + $(this).val(text);
  142 + $(this).addClass('active');
  143 + }
  144 + });
  145 + }
  146 +});
  147 +
  148 +</script>
  149 +{% endblock %}
... ...