Sets the language for Q string variables. Currently not used, except for Q.UXTimeParse().
This is the heart of most Q features. On its own, Q.Core is an impressive set of methods and features, though only when coupled with other parts of the Q Library, it really shines. Q.Core is the groundwork, the base layer for all the advanced features of Q, including:
Q.Core lives in its own namespace, Q.*
, or Window.Q.*
, if you want to be precise.
Plugins created and registered via Q become proper jQuery plugins, accessible in all the standard ways.
To find out more about this, make sure to read the Q.PluginFactory
documentation.
There's been a lot said and written about HTML5. Most browsers support at least part of the specification, yet many developers are reluctant to use it. Adoption of at least several HTML5 features will allow you to leverage your Q experience and make your "rapid development" truly that.
If you want to use other features of Q, Q.Core is a must for you. Without it, the whole library simply won't work. But you don't need to limit yourself only to using it for Q related stuff. Q.Core provides features and methods that are Q-agnostic and can also be employed independently.
Q.Core is written as a static object, meaning that you don't need to run any initialization before using its features. All of its methods are available immediately after the library has been loaded.
To start using Q.Core, simply place the Q Library somewhere in your web application's folders, and
refer to Q.Core using the <script>
HTML tag:
<script type="text/javascript" src="path_to_file/q.core.js"></script>
There isn't anything arcane about using Q.Core. It consists of straightforward methods that you
call in an equally straightforward way. All methods have a return value; some return results of their
operation (e.g. Q.GUID()
or Q.HTML.decode()
), others return reference to
Q Library itself (e.g. Q.eventTrigger()
or Q.dropEvent()
).
This ensures that you can chain function calls wherever it makes sense to, and expect some kind of meaningful response from the rest.
For your comfort, Q.Core offers a few predefined properties that you can change at any point.
Basic configuration options for Q are available under Q.options
.
Sets the language for Q string variables. Currently not used, except for Q.UXTimeParse().
While using custom logging of events and actions is a great way to improve development, it may be a major memory hog. In order to limit memory usage, Q introduces this configuration property.
Each log request contains a priority, default 0. Before Q actually logs the record, it checks whether its priority equals to or exceeds loggingMinimumPriority value.
Most log requests come with value 0. By setting Q.loggingMinimumPriority
to
1, you'll prevent most records from being logged. Note that errors come with priority 1,
which means they would be recorded.
These are the methods that help Q become the ultimate tool for your rapid development needs.
Returns
an Integer, which is the length
of current Stack.
0
when empty/null.
false
when empty/null.
arguments
to this property, you will record an array of arguments
exactly the way your function had received them.null
.
false
when empty/null.
null
.
Instead of a whole Object, you may also provide only a String containing the text of the message to be recorded. If you do that, the optional properties will be set to their defaults.
Returns an Array of all records in the Stack, matching the filter criteria (if any were specified).
Returns an instance of Q.
This function allows you to trigger an existing event within your plugin. It is one of the key components to a fully customizable event model.
instance
with value this, so that
the event handler can properly address the instance which triggered it:
Note that plugins created using Q.PluginFactory also use event methods, though they're not
using the ones from Q.Core. Therefore you would call this.eventTrigger
within
a plugin, instead of Q.eventTrigger
.
Returns an instance of Q.
This function removes either a single event handler from the queue, or drops the entire queue of event handlers.
Note that plugins created using Q.PluginFactory also use event methods, though they're not
using the ones from Q.Core. Therefore you would call this.dropEvent
within
a plugin, instead of Q.dropEvent
.
Returns String
This Object encapsulates two key methods for handling HTML Strings: Encode and Decode. While many implementations strive to process strings using regular expressions, Q uses a temporary DOM node to perform the transformation in a fast and reliable way.
$('#MyDOM').html()
.
HTML.encode()
.
Returns String
This Object encapsulates two key methods for handling Base64: Encode and Decode. It is quite rare to encode and decode Base64 in Javascript, but since Q supports JSON and fully AJAX-driven interfaces, this feature will eventually be used.
Returns String
This function provides a way to use parts of HTML as templates for rendering data. To achieve this,
the HTML code needs to be wrapped in HTML tag <template>
, which is a part of HTML5 specification.
Note that <template>
is not rendered by browser, and therefore its contents are hidden from
users, yet still available to Q.Template.
A <template>
to be used by Q.Template needs to have two attributes assigned:
id, and data-content. The id has to be unique in the page scope, and the
data-content attribute needs to have value "QTemplate". That is how Q recognizes <template>
that is assigned for its use.
Notice the placeholders {Q:lastname}
and {Q:firstname}
. As you may have
guessed, these will get replaced by actual values of variables lastname and firstname.
There placeholders can be used anywhere in the template; it is therefore very easy to fill in parts of
text, URL, CSS classes, etc. At the same time, you are keeping HTML code separate from data, which
is a great thing - and any software architect and webdeveloper will agree.
The very simple filter function above would return true only for records where the lastname is "Smith", and so only the "Bob Smith" item would get rendered.
The example above is a very simple one; your filter functions may be much more complex, even up to the point where they perform AJAX requests, themselves.
Q.Template, naturally, doesn't magically understand where you want the results displayed.
To actually print them out into your web page, you'll need to use jQuery's function $.html()
.
For the sake of being thorough, let's take a look at what a very plain page with a very plain use of
Q.Template looks like:
What happens in the example above? Well, Q.Template finds the HTML element <template>
that is identified as "MyTemplate". If it didn't, it would fail without throwing a JS error, but it would record an
error in the Stack, so you could retrieve it using Q.GetStack() method.
Next the method loads the data provided as 2nd parameter. Since the data is already an Array, Q.Template leaves it unchanged. Then it begins looping over the data Array. Because we have also provided a 3rd parameter (a filter), Q.Template evaluates the filter function and provides it the entire row of data.
If the filter function returns true, Q.Template proceeds with parsing the template, processing the variables and inserting their values into marked places. Then the processed HTML code is stored in local cache until processing of all data is complete.
Finally, Q.Template returns the cached results as a single string of HTML code. That is where jQuery function $.html() receives the processed data and inserts them into the right place. The example would result in this:
The actual value of this method begins to show more as you'll have more data, an more complex structures to render.
That's right, Q.Template can render much more complex structures, including nested Objects or Arrays. A "Guide To Advanced Templating" is being prepared.
Returns String
This function returns a Unique Identifier string, generated according to Version 4 UUID specification.
This method does not accept any parameters.
Returns String
This function returns a string representation of a human-readable date and time. The function calculates how much time has passed since the provided date/time, and return a human-readable format of a time (and date when applicable).
A date/time which falls on today will only show time. A date/time which happened yesterday, will read "Yesterday at hh:mm". A date/time which happened two days ago, will read "Two days ago, at hh:mm". Anything older than that will display a date and time.