var hasTouch = 'ontouchend' in window, eventTimer; var moveDirection = 'undefined', startX, startY, deltaX, deltaY, mouseDown = false; function addTouchEvents(element){ if (hasTouch) { element.addEventListener("touchstart", touch2Mouse, true); element.addEventListener("touchmove", touch2Mouse, true); element.addEventListener("touchend", touch2Mouse, true); } } function touch2Mouse(e) { var theTouch = e.changedTouches[0]; var mouseEv; switch(e.type) { case "touchstart": mouseEv="mousedown"; break; case "touchend": mouseEv="mouseup"; break; case "touchmove": mouseEv="mousemove"; break; default: return; } if (mouseEv == "mousedown") { eventTimer = (new Date()).getTime(); startX = theTouch.clientX; startY = theTouch.clientY; mouseDown = true; } if (mouseEv == "mouseup") { if ((new Date()).getTime() - eventTimer <= 500) { mouseEv = "click"; } else if ((new Date()).getTime() - eventTimer > 1000) { mouseEv = "longclick"; } eventTimer = 0; mouseDown = false; } if (mouseEv == "mousemove") { if (mouseDown) { deltaX = theTouch.clientX - startX; deltaY = theTouch.clientY - startY; moveDirection = deltaX > deltaY ? 'horizontal' : 'vertical'; } } var mouseEvent = document.createEvent("MouseEvent"); mouseEvent.initMouseEvent(mouseEv, true, true, window, 1, theTouch.screenX, theTouch.screenY, theTouch.clientX, theTouch.clientY, false, false, false, false, 0, null); theTouch.target.dispatchEvent(mouseEvent); e.preventDefault(); } (function( $ ) { $.widget("metro.tileTransform", { version: "1.1.1", options: { }, _create: function(){ var element = this.element; var dim = {w: element.width(), h: element.height()}; element.on('mousedown.metroTransform', function(e){ var X = e.pageX - $(this).offset().left, Y = e.pageY - $(this).offset().top; var transform = 'top'; if (X < dim.w * 1/3 && (Y < dim.h * 1/2 || Y > dim.h * 1/2 )) { transform = 'left'; } else if (X > dim.w * 2/3 && (Y < dim.h * 1/2 || Y > dim.h * 1/2 )) { transform = 'right' } else if (X > dim.w*1/3 && X dim.h/2) { transform = 'bottom'; } setTimeout(function ($this) { $this.addClass("tile-transform-"+transform); }, 10, $(this)); }); element.on('mouseup.metroTransform', function(){ setTimeout(function ($this) { $this.removeClass("tile-transform-left") .removeClass("tile-transform-right") .removeClass("tile-transform-top") .removeClass("tile-transform-bottom"); }, 10, $(this)); }); element.on('mouseleave.metroTransform', function(){ $(this) .removeClass("tile-transform-left") .removeClass("tile-transform-right") .removeClass("tile-transform-top") .removeClass("tile-transform-bottom"); }); }, _destroy: function(){ }, _setOption: function(key, value){ this._super('_setOption', key, value); } }) $.widget("metro.inputControl", { version: "1.0.0", options: { }, _create: function(){ var that = this, control = this.element; if (control.hasClass('text')) { this.initTextInput(control, that); } else if (control.hasClass('password')) { this.initPasswordInput(control, that); } else if (control.hasClass('checkbox') || control.hasClass('radio') || control.hasClass('switch')) { this.initCheckboxInput(control, that); } else if (control.hasClass('file')) { this.initFileInput(control, that); } }, initCheckboxInput: function(el, that) { }, initFileInput: function(el, that){ var button, input, wrapper; wrapper = $(""); button = el.children('.btn-file'); input = el.children('input[type="file"]'); input.css('z-index', 0); wrapper.insertAfter(input); input.attr('tabindex', '-1'); //button.attr('tabindex', '-1'); button.attr('type', 'button'); input.on('change', function(){ var val = $(this).val(); if (val != '') { wrapper.val(val); } }); button.on('click', function(){ input.trigger('click'); }); }, initTextInput: function(el, that){ var button = el.children('.btn-clear'), input = el.children('input[type=text]'); //console.log(button.length); //button = el.children('.btn-clear'); if (button.length == 0) return; button.attr('tabindex', '-1'); button.attr('type', 'button'); button.on('click', function(){ input = el.children('input'); if (input.prop('readonly')) return; input.val(''); input.focus(); that._trigger("onClear", null, el); }); if (!input.attr("disabled")) input.on('click', function(){$(this).focus();}); }, initPasswordInput: function(el, that){ var button = el.children('.btn-reveal'), input = el.children('input[type=password]'); var wrapper; if (button.length == 0) return; button.attr('tabindex', '-1'); button.attr('type', 'button'); button.on('mousedown', function(e){ input.attr('type', 'text'); //e.preventDefault(); // wrapper = el.find(".__wrapper__").length == 0 ? $('') : el.find(".__wrapper__"); // // input.hide(); // wrapper.appendTo(that.element); // wrapper.val(input.val()); // // that._trigger("onPasswordShow", null, that.element); }); button.on('mouseup, mouseleave, blur', function(e){ input.attr('type', 'password').focus(); //e.preventDefault(); // input.show().focus(); // wrapper.remove(); // // that._trigger("onPasswordHide", null, that.element); }); if (!input.attr("disabled")) input.on('click', function(){$(this).focus();}); }, _destroy: function(){ }, _setOption: function(key, value){ this._super('_setOption', key, value); } }); $.widget("metro.inputTransform", { version: "1.0.0", options: { transformType: "text" }, _create: function(){ var that = this, element = this.element, inputType; var checkTransform = element.parent().hasClass("input-control"); if (checkTransform) return; inputType = element.get(0).tagName.toLowerCase(); if (inputType == "textarea") { this.options.transformType = "textarea"; } else if (inputType == "select") { this.options.transformType = "select"; } else { if (element.data('transformType') != undefined) { this.options.transformType = element.data('transformType'); } else { this.options.transformType = element.attr("type"); } } var control = undefined; switch (this.options.transformType) { case "password": control = this._createInputPassword(); break; case "file": control = this._createInputFile(); break; case "checkbox": control = this._createInputCheckbox(); break; case "radio": control = this._createInputRadio(); break; case "switch": control = this._createInputSwitch(); break; case "select": control = this._createInputSelect(); break; case "textarea": control = this._createInputTextarea(); break; case "search": control = this._createInputSearch(); break; case "email": control = this._createInputEmail(); break; case "tel": control = this._createInputTel(); break; case "number": control = this._createInputNum(); break; default: control = this._createInputText(); } control.inputControl(); }, _createInputTextarea: function(){ var element = this.element; var wrapper = $("
").addClass("input-control").addClass("textarea"); var clone = element.clone(true); var parent = element.parent(); clone.appendTo(wrapper); wrapper.insertBefore(element); element.remove(); return wrapper; }, _createInputSelect: function(){ var element = this.element; var wrapper = $("
").addClass("input-control").addClass("select"); var clone = element.clone(true); var parent = element.parent(); clone.val(element.val()).appendTo(wrapper); wrapper.insertBefore(element); element.remove(); return wrapper; }, _createInputSwitch: function(){ var element = this.element; var wrapper = $("
").addClass("input-control").addClass("switch"); var label = $("