Posts Tagged with java

Displaying 1-10 of 16 results.
Wiki: Loads a JavaScript file asynchronously with a callback, like jQuery's $.getScript() except without jQuerywiki
posted by admin on April 13, 2017

function j(u, c) {
var h = document.getElementsByTagName('head')[0], s = document.createElement('script');
s.async = true; s.src = u;
s.onload = s.onreadystatechange = function () {
if (!s.readyState || /loaded|complete/.test(s.readyState)) {
s.onload = s.onreadystatechange = null; if (h && s.parentNode) { h.removeChild(s) } s = undefined;
if (c) { c() }
}
};
h.insertBefore(s, h.firstChild);
}
Read more
Wiki: How to make an AJAX call without jQuery with GET and POST?wiki
posted by admin on March 27, 2017
Using the following snippet you can do similar things pretty easily, like this:

ajax.get('/test.php', {foo: 'bar'}, function() {});

Here is the snippet:

var ajax = {};
ajax.x = function () {
if (typeof XMLHttpRequest !== 'undefined') {
return new XMLHttpRequest();
}
var versions = [
"MSXML2.XmlHttp.6.0",
"MSXML2.XmlHttp.5.0",
"MSXML2.XmlHttp.4.0",
"MSXML2.XmlHttp.3.0",
"MSXML2.XmlHttp.2.0",
"Microsoft.XmlHttp"
];

var xhr;
for (var i = 0; i < versions.length; i++) {
try {
xhr = new ActiveXObject(versions[i]);
break;
} catch (e) {
}
}
return xhr;
};

ajax.send = function (url, callback, method, data, async) {
if (async === undefined) {
async = true;
}
var x = ajax.x();
x.open(method, url, async);
x.onreadystatechange = function () {
if (x.readyState == 4) {
callback(x.responseText)
}
};
if (method == 'POST') {
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
}
x.send(data)
};

ajax.get = function (url, data, callback, async) {
var query = [];
for (var key in data) {
query.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key]));
}
ajax.send(url + (query.length ? '?' + query.join('&') : ''), callback, 'GET', null, async)
};

ajax.post = function (url, data, callback, async) {
var query = [];
for (var key in data) {
query.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key]));
}
ajax.send(url, callback, 'POST', query.join('&'), async)
};
Read more
Wiki: PHPStorm FIX - not working hotkey CTRL + keys functionalitywiki
posted by admin on February 27, 2017
In most java-application with a GUI on Ubuntu in Russian layout is not working hotkeys, even the standard Ctrl + C and Ctrl + V. But a good man, named Michael Zheludkov wrote fix this bug, for which he had great thanks.
Installation
Clone repository in the folder ~ / fix /:

git clone https://github.com/zheludkovm/LinuxJavaFixes.git fix

Открываем конфиг приложения: or edit with GEDIT editor

nano /opt/PhpStorm/bin/phpstorm64.vmoptions

Add the following line to the fix:

-javaagent:/home/{user}/fix/build/LinuxJavaFixes-1.0.0-SNAPSHOT.jar

Replace {user} to your Ubuntu user UsernameRead more
Resolved: Javascript jSnow plugin Uncaught TypeError: Cannot read property 'msie' of undefined
posted by admin on December 19, 2016
I use jsnow.js javascript plugin and now I have got this error.

$(document).ready(function () {
$().jSnow({zIndex : 999999999});
})

Please help to resolve itRead more
Resolved: Javascript body onclick function event
posted by admin on December 15, 2016
I have a function and onmousemove event in body attribute.
JS

function mouseShowHandler(e){

e = e || window.event


if (e.pageX == null && e.clientX != null ) {

var html = document.documentElement

var body = document.body

e.pageX = e.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - (html.clientLeft || 0)

e.pageY = e.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - (html.clientTop || 0)



}
xx=e.pageX
yy=e.pageY
}


HTML

...
<body onmousemove="mouseShowHandler(event)">
...

It is working fine, But I want to event handler to my script file, and remove from bodyRead more
Wiki: Google Maps API Maps JavaScript API Place Autocompletewiki
posted by admin on October 12, 2016

<!DOCTYPE html>
<html>
<head>
<title>Place Autocomplete</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
.controls {
margin-top: 10px;
border: 1px solid transparent;
border-radius: 2px 0 0 2px;
box-sizing: border-box;
-moz-box-sizing: border-box;
height: 32px;
outline: none;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

#pac-input {
background-color: #fff;
font-family: Roboto;
font-size: 15px;
font-weight: 300;
margin-left: 12px;
padding: 0 11px 0 13px;
text-overflow: ellipsis;
width: 300px;
}

#pac-input:focus {
border-color: #4d90fe;
}

.pac-container {
font-family: Roboto;
}

#type-selector {
color: #fff;
background-color: #4d90fe;
padding: 5px 11px 0px 11px;
}

#type-selector label {
font-family: Roboto;
font-size: 13px;
font-weight: 300;
}

</style>
</head>
<body>
<input id="pac-input" class="controls" type="text"
placeholder="Enter a location">
<div id="type-selector" class="controls">
<input type="radio" name="type" id="changetype-all" checked="checked">
<label for="changetype-all">All</label>

<input type="radio" name="type" id="changetype-establishment">
<label for="changetype-establishment">Establishments</label>

<input type="radio" name="type" id="changetype-address">
<label for="changetype-address">Addresses</label>

<input type="radio" name="type" id="changetype-geocode">
<label for="changetype-geocode">Geocodes</label>
</div>
<div id="map"></div>

<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -33.8688, lng: 151.2195},
zoom: 13
});
var input = /** @type {!HTMLInputElement} */(
document.getElementById('pac-input'));

var types = document.getElementById('type-selector');
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(types);

var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo('bounds', map);

var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
map: map,
anchorPoint: new google.maps.Point(0, -29)
});

autocomplete.addListener('place_changed', function() {
infowindow.close();
marker.setVisible(false);
var place = autocomplete.getPlace();
if (!place.geometry) {
window.alert("Autocomplete's returned place contains no geometry");
return;
}

// If the place has a geometry, then present it on a map.
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17); // Why 17? Because it looks good.
}
marker.setIcon(/** @type {google.maps.Icon} */({
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(35, 35)
}));
marker.setPosition(place.geometry.location);
marker.setVisible(true);

var address = '';
if (place.address_components) {
address = [
(place.address_components[0] && place.address_components[0].short_name || ''),
(place.address_components[1] && place.address_components[1].short_name || ''),
(place.address_components[2] && place.address_components[2].short_name || '')
].join(' ');
}

infowindow.setContent('<div><strong>' + place.name + '</strong>
' + address);
infowindow.open(map, marker);
});

// Sets a listener on a radio button to change the filter type on Places
// Autocomplete.
function setupClickListener(id, types) {
var radioButton = document.getElementById(id);
radioButton.addEventListener('click', function() {
autocomplete.setTypes(types);
});
}

setupClickListener('changetype-all', []);
setupClickListener('changetype-address', ['address']);
setupClickListener('changetype-establishment', ['establishment']);
setupClickListener('changetype-geocode', ['geocode']);
}

</script>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&signed_in=true&libraries=places&callback=initMap"
async defer></script>
</body>
</html>
Read more
Resolved: Replace %2C with a comma in javascript?
posted by admin on June 18, 2016
I get string from URL

#&q=car&category=Car%20Audio%2CAccessories&brand=

%2C is comma in url, and I want to recover my string with comma

#&q=car&category=Car%20Audio,Accessories&brand=
Read more
Resolved: Submit form on change of dropdown list
posted by admin on April 26, 2016
I have SELECT dropdown list

<form method="GET" >
<select id="id_period" name="period">
<option value="day">day</option>
<option value="week">week</option>
<option value="month">month</option>
<option value="all" selected="selected">all time</option>
</select>
</form>

I want to submit form on changeRead more
Resolved: JavaScript replace or remove words from string using one function
posted by admin on April 23, 2016
I have string and I want to replace or remove words combination. Not one by one, not using

str = str.replace("green", "red");
str = str.replace("blue", "red")
etc...


I want something like

str.function("words combination", "red")
Read more
Resolved: Yii CGridView pagination not working and alert 500 or 404 error
posted by admin on April 23, 2016
I have trouble about cgridview pagination.
I am using admin page(/{module}/admin that) generated by gii.
it has search form and grid with pagination. its work well without urlmanager

but my team have create urlmanager rule long ago.

'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

'<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>'=>'<module>/<controller>/<action>',

),
),


when I use admin page with this urlmanager rule. It has some problem.
- if not using grid sort or pagination. I can filter in grid and form.
- but if using sort or pagination. I can not filtering in grid and form anymore.

page link is wierd and i think because of some attribute(params) are null like this

/{module}/{controller}/admin/BookManageMain%5Bbmm_code%5D//BookManageMain%5Bbmm_tid%5D/2/.../BookManageMain_page/2/ajax/book-manage-main-grid

if I am copy this url to another tab and Its can not filtering in grid and form too.
but if I remove attribute that has null value(BookManageMain%5Bbmm_code%5D//) I can filter grid and form.

/{module}/{controller}/admin/BookManageMain%5Bbmm_tid%5D/2/.../BookManageMain_page/2/ajax/book-manage-main-grid

console log (not sure filter use POST and sort/page use GET)

before click pagerlink or sorting
.../{controller}/action?BookManageMain%5Bbmm_code%5D=&BookManageMain%5Bbmm_tid%5D=2&...&BookManageMain_page=1&ajax=book-manage-main-grid

after click

.../{controller}/action/BookManageMain%5Bbmm_code%5D//BookManageMain%5Bbmm_tid%5D/2/.../BookManageMain_page/2/ajax/book-manage-main-grid
Read more