Class JavaScriptHelper
Class JavaScriptHelper: used to help with generating javascript code
Methods summary
public static
string
|
#
customDataInsertion( QControl $objControl, string $strKey, string $strValue )
Returns javascript that on execution will insert the value $strValue into the DOM element corresponding to
the $objControl using the key $strKey
Returns javascript that on execution will insert the value $strValue into the DOM element corresponding to
the $objControl using the key $strKey
Parameters
- $objControl
- $strKey
- $strValue
- any javascript variable or object
Returns
string data insertion javascript
|
public static
string
|
#
customDataRetrieval( QControl $objControl, string $strKey, string $strValue )
Returns javascript that on execution will retrieve the value from the DOM element corresponding to
the $objControl using the key $strKey and assign it to the javascript variable $strValue.
Returns javascript that on execution will retrieve the value from the DOM element corresponding to
the $objControl using the key $strKey and assign it to the javascript variable $strValue.
Parameters
- $objControl
- $strKey
- $strValue
Returns
string data retrieval javascript
|
public static
string
|
#
dataNameFromCamelCase( $strName )
Helper class to convert a name from camel case to using dashes to separated words.
data-* html attributes have special conversion rules. Key names should always be lower case. Dashes in the
name get converted to camel case javascript variable names by jQuery.
For example, if you want to pass the value with key name "testVar" from PHP to javascript by printing it in
the html, you would use this function to help convert it to "data-test-var", after which you can retrieve
in in javascript by calling ".data('testVar')". on the object.
Helper class to convert a name from camel case to using dashes to separated words.
data-* html attributes have special conversion rules. Key names should always be lower case. Dashes in the
name get converted to camel case javascript variable names by jQuery.
For example, if you want to pass the value with key name "testVar" from PHP to javascript by printing it in
the html, you would use this function to help convert it to "data-test-var", after which you can retrieve
in in javascript by calling ".data('testVar')". on the object.
Parameters
Returns
string
Throws
|
public static
string
|
#
dataNameToCamelCase( $strName )
Converts an html data attribute name to camelCase.
Converts an html data attribute name to camelCase.
Parameters
Returns
string
|
public static
|
|
public static
string
|
#
toJsObject( mixed $objValue )
Recursively convert a php object to a javascript object.
If the $objValue is an object other than Date and has a toJsObject() method, the method will be called
to perform the conversion. Array values are recursively converted as well.
Recursively convert a php object to a javascript object.
If the $objValue is an object other than Date and has a toJsObject() method, the method will be called
to perform the conversion. Array values are recursively converted as well.
This string is designed to create the object if it was directly output to the browser. See toJSON below
for an equivalent version that is passable through a json interface.
Parameters
- $objValue
- the php object to convert
Returns
string javascript representation of the php object
|
public static
string
|
#
toJSON( mixed $objValue )
Our specialized json encoder. Strings will be converted to UTF-8. Arrays will be recursively searched and
both keys and values made UTF-8. Objects will be converted with json_encode, and so objects that need a special
encoding should implement the jsonSerializable interface. See below
Our specialized json encoder. Strings will be converted to UTF-8. Arrays will be recursively searched and
both keys and values made UTF-8. Objects will be converted with json_encode, and so objects that need a special
encoding should implement the jsonSerializable interface. See below
Parameters
Returns
string
|
public static
mixed
|
#
MakeJsonEncodable( mixed $objValue )
Convert an object to a structure that we can call json_encode on. This is particularly meant for the purpose of
sending json data to qcubed.js through ajax, but can be used for other things as well.
Convert an object to a structure that we can call json_encode on. This is particularly meant for the purpose of
sending json data to qcubed.js through ajax, but can be used for other things as well.
PHP 5.4 has a new jsonSerializable interface that objects should use to modify their encoding if needed. Otherwise,
public member variables will be encoded. The goal of object serialization should be to be able to send it
to qcubed.unpackParams in qcubed.js to create the javascript form of the object. This decoder will look for objects
that have the 'qObjType' key set and send the object to the special unpacker.
DateTime handling is absent below. DateTime objects will get converted, but not in a very useful way. If you
are using strict DateTime objects (not likely since the framework normally uses QDateTime for all date objects),
you should convert them to QDateTime objects before sending them here.
Parameters
Returns
mixed
|
public static
string
|
#
TerminateScript( $strScript )
Utility function to make sure a script is terminated with a semicolon.
Utility function to make sure a script is terminated with a semicolon.
Parameters
Returns
string
|