Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Wednesday, 2 December 2015

My APEX cheatbook (For Newbies?)

Data Convertion.
- To String: String.valueOf(data);
- To Integer: Integer.valueOf(data);

Stringified(Serialized) JSON to Apex Data.
private static void doSomething(String JSONString) {
  Map<String, Object> myJSON = (Map<String, Object>) JSON.deserializeUntyped(JSONString);
  Integer something = myJSON.get('key');
}

Execute Apex Class from Browser Client.
Apex Class:
Global with sharing class SomeClass {
  // Dummy constructer
  public SomeClass() {}

  // Important, without RemoteAction, it wont work
  @RemoteAction
  public static String someFunction() {
    return 'success';
  }
}

Browser Client Side(JavaScript):
<apex:page controller="SomeClass">
<script>
SomeClass.someFunction(function(result, event) {
  console.log(result); // outputs 'success';
});
</script>
</apex:page>


To be continue...?

Thursday, 2 August 2012

Scrollable fixed contents with HTML and CSS, with some jQuery

Do you have a task to make a scrollable fixed element where the main content is behind it?
Plus, it must contain native application-like animation?
AND IT MUST BE IN HTML + CSS?

Well, I just figured it out a way for it.
I made this when my colleague asked me whether HTML + CSS able to scroll fixed element while I thinking about the "log part" of my BADV-project template.

What came out is this.
(Notet that it's just a rought sample. Android / iOS may react different)


content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content
content

Well, it's a dirty work and all work-in-progress code / comments are inside.
(Note that some css values were modified to suit into this blog. Example, position: fixed to absolute)

Original code:
http://dev.k2-rnd.com/samples/slide.zip

Tuesday, 24 July 2012

How to locate yourself using HTML5 Geolocation (obtain current location's latitue/longtitude)

To locate your current position.

What you need is just the following JavaScript code.


var coordinates;
function updatePosition(position) {
    var lat = position.coords.latitude;
    var lon = position.coords.longitude;
    coordinates = [lat, lon];
}

function handleError(positionError) {
    alert('Attempt to get location failed: ' + positionError.message);
}

var gps = navigator.geolocation;
gps.getCurrentPosition(updatePosition, handleError);
alert(coordinates);

Yeap, thats all what you need to get your current location's latitude and longtitude.
And it's works on ALMOST all browsers. (Argh,  android device before v2.1 not supported.)
Mind that, the latitude and longtitude obtained it's not 100% accurate.
It depends on ISP and carrier for the accuracy.

Example, PC browser that access through wired line ISP would obtain the nearest relay station's location. Where the wi-fi user gets a closer match.

Monday, 11 June 2012

How to play HTML5 audio through JavaScript

A simple memo of how to play HTML5 audio using JavaScript

var audioElement = new Audio();
audioElement.src = 'http://www.somesite.com/audioresource.ogg';
audioElement.load();
audioElement.play();
That's all. Is that simple :D

Note that some browser do not supports ogg formats.
You might want to encode that specified format to support playback for that particular browser.
Well, I don't care about those browsers though.

As for mobile browsers... (MobileSafari, Android Browser)
Unfortunately they do not work as planned.

Reference :
http://www.phoboslab.org/log/2011/03/the-state-of-html5-audio
http://remysharp.com/2010/12/23/audio-sprites/
http://24ways.org/2010/the-state-of-html5-audio

It's year 2012 and Apple haven't solve that problem yet...
I do not owned an Android Device, I do not know is it fixed or not...