mootools

DOM Element Width before Appended to DOM

一曲冷凌霜 提交于 2019-11-28 08:08:31
I'm sure the answer is no, but is it possible to determine the width of an element before it is appended to the DOM? Once it's appended, I know I can use offsetWidth and offsetHeight. Thanks The trick is to show the element (display:block) but also hide it (visibility:hidden) and to set it’s position to absolute so that it doesn’t affect the page flow. The MooTools Element.Measure class does this, as Oscar mentioned. jpadvo The Mootools Element.Measure functionality that Oscar mentioned is awesome. For those that use jQuery, here's a quick plugin that accomplishes the same thing: $.fn.measure

preg_match in JavaScript?

℡╲_俬逩灬. 提交于 2019-11-28 07:07:23
Is it possible in JavaScript to do something like preg_match does in PHP ? I would like to be able to get two numbers from string: var text = 'price[5][68]'; into two separated variables: var productId = 5; var shopId = 68; Edit: I also use MooTools if it would help. godswearhats JavaScript has a RegExp object which does what you want. The String object has a match() function that will help you out. var matches = text.match(/price\[(\d+)\]\[(\d+)\]/); var text = 'price[5][68]'; var regex = /price\[(\d+)\]\[(\d+)\]/gi; match = regex.exec(text); match[1] and match[2] will contain the numbers you

Select text and then calculate its distance from top with Javascript?

人走茶凉 提交于 2019-11-28 03:32:22
问题 Is it possible with JavaScript to find a given string of text on a webpage, and then calculate its distance (in pixels) from the top of the page? If so, an example would be appreciated. 回答1: Update: made more robust. A fun and interactive demo: See it in action, here. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html> <head> <title>Word Finder Fun</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style type="text

MooTools CORS request vs native Javascript

只愿长相守 提交于 2019-11-28 01:44:33
问题 I have this MooTools code: new Request.JSON({ method: 'POST', url: URL, /*URL TO ANOTHER DOMAIN*/ onSuccess: function(r){ callback(r); } }).post(data); And this code doesn't send POST requests (OPTIONS only)... Look at the code below (it works great): var http = null, params = Object.toQueryString(data); try { http = new XMLHttpRequest(); } catch (e) { try { http = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { http = null

Retrieving percentage CSS values (in firefox)

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 00:59:57
I have a problem retrieving the exact css property value (in '%') on firefox. Suppose we have this extremely simple markup: <div id="box">box</div> and this css: #box{ width:200px; height:200px; left:10%; position:absolute; background:red; } and I'd like to retrieve the left position (in '%') by js It's obv very easy with mootools (demo -> http://jsfiddle.net/steweb/AWdzB/ ): var left = $('box').getStyle('left'); or jQuery (demo -> http://jsfiddle.net/steweb/RaVyU/ ): var left = $('#box').css('left'); or by plain js (demo -> http://jsfiddle.net/steweb/tUAKA/ ): function getStyle(el,styleProp){

How to convert form data to object using MooTools

China☆狼群 提交于 2019-11-27 23:39:46
问题 I would like to convert an entire form of data to a javascript object. <form id='myform'> <input type='text' name='field1' value='foo'> <input type='text' name='field2' value='bar'> </form> would convert to a javascript object... { field1: 'foo', field2: 'bar' } 回答1: In MooTools you can do easy trick how to convert all forms values into the Object: var formObjects=$('myform').toQueryString().parseQueryString(); Convert to JSON: var formJson=JSON.encode(formObjects); 回答2: just write your own

Change the options array of a select list

随声附和 提交于 2019-11-27 21:57:36
Is there a way to change the options array of an html select list using javascript or mootools? I need to replace the entire options set with a new one. In my ajax response I receive an array filled in with with the new HTML options, so I try to empty the old list and add new values as follows $('element').options.length=0; for (i=0; i<newSet.length; i++) { $('element').options[i]=newSet[i]; } The above code gives me an uncaught exception on the line inside the loop. uncaught exception: [Exception... "Unexpected error" nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)" location: "JS frame Just to

Javascript detect scrollbar in textarea

陌路散爱 提交于 2019-11-27 21:20:51
I was wondering if anybody knows how I would go about detecting when the scrollbar appears inside a textarea . I am currently using mootools for my JavaScript and I am having issues getting it to detect a scrollbar. Tommaso Taruffi function has_scrollbar(elem_id) { const elem = document.getElementById(elem_id); if (elem.clientHeight < elem.scrollHeight) alert("The element has a vertical scrollbar!"); else alert("The element doesn't have a vertical scrollbar."); } See this jsFiddle http://jsfiddle.net/qKNXH/ Capt Otis Tommaso's solution works perfectly, even with a text area. But if the user

How can I focus on an input field when a phonegap page loads?

半世苍凉 提交于 2019-11-27 15:07:04
I would like to focus on a text input in a PhoneGap application when the page loads. I have tried the MooTools version $('entry').focus(); and document.getElementById('entry').focus() when the DOM is ready. This works fine when the HTML page is viewed in a normal web browser, but in the iPhone simulator running PhoneGap, it doesn't work. Is there a way to focus on a form field for iPhones that forces the virtual keyboard to appear? As of iOS 6, the UIWebView class has a property called "keyboardDisplayRequiresUserAction". If you want to programmatically focus text form elements, set this to

Retrieve width/height of a css3 scaled element

时间秒杀一切 提交于 2019-11-27 14:34:55
I'm fighting against an oddity (I think) of the offsetWidth property. this is the scenario: I've got, let's say, a span tag, in my js, at a certain point I perform a css3 transform to this element, like: el.set('styles', { 'transform':'scale('+scale+', '+scale+')', /* As things would be in a normal world */ '-ms-transform':'scale('+scale+', '+scale+')', /* IE 9 */ '-moz-transform':'scale('+scale+', '+scale+')', /* Moz */ '-webkit-transform':'scale('+scale+', '+scale+')', /* Safari / Chrome */ '-o-transform':'scale('+scale+')' /* Oprah Winfrey */ }); w = el.getWidth(); console.log('after