jQuery-Komponente
/**
* Zuweisung
* $('#placeholder').asignAlvineComponent(Alvine.jQuery.Extension.Example,{key:'value'});
* Abfrage eines Wertes
* $('#placeholder').get(0).Alvine.Example.getSetting('key');
*/
/**
* Konsole-Logger als Fallback
*
* @type Window.console|Console
*/
var console = window.console||{};
console.error = console.error||console.log||function() {};
/**
* Plugin-Definition
*
* @param {type} global
*
* @returns {undefined}
*/
(function(global) {
/**
* Strikte Prüfung
* https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Strict_mode/wechsel_zum_strict_mode
**/
"use strict";
/**
* Beim Packen (minify) nicht durch andere Namen ersetzen,
* damit die API erhalten bleibt.
*/
"Example:nomunge";
/**
* Im Scope verwendete Variablen
*/
var NAMESPACE, PLUGINNAME, DEFAULTS, window, Object, document, navigator, jQuery, JSON, Alvine;
/**
* KONSTANTEN ###########################################
*/
NAMESPACE = 'Alvine.jQuery.Extension';
PLUGINNAME = 'Example';
DEFAULTS = {
/**
* @type {String} Required version of the framework
*/
'REQUIREDALVINEFRAMEWORKVERSION': '1.0.0',
/**
* @type {String} String Required Version jQuery
*/
'REQUIREDJQUERYVERSION': '2.1.1'
};
/**
* EIGENSCHAFTEN ###################################
*/
/**
* @type object Window
*/
window = global.window;
/**
* @type object
*/
Object = global.Object;
/**
* @type object Dokument
*/
document = global.document;
/**
* @type object Navigatorobjekt
*/
navigator = global.navigator;
/**
* @type object JQUERY
*/
jQuery = global.jQuery||function() {
return {};
};
/**
* @type JSON
*/
JSON = global.JSON;
/**
* Zentrales Alvine-Objekt
*
* @type Objekt
*/
Alvine = window.Alvine;
try {
/**
* Prüfen ob Alvine und jQuery verfügbar
*/
if(typeof Alvine!=='object'
||typeof Alvine.Namespace!=='function'
||!(Alvine instanceof Alvine.Namespace)) {
console.error('Alvine javascript framework missing.');
return null;
}
if((typeof jQuery!=='function'&&typeof jQuery!=='object')
||!jQuery.fn===undefined
||typeof jQuery.fn.jquery!=='string') {
console.error('jQuery missing.');
return null;
}
/** Version check jQuery */
if((new Alvine.Types.Version(jQuery.fn.jquery)).compareTo(DEFAULTS.REQUIREDJQUERYVERSION)===-1) {
console.error('jQuery Version '+DEFAULTS.REQUIREDJQUERYVERSION+' required.');
}
/** version check Alvine */
if(Alvine.getVersion().compareTo(DEFAULTS.REQUIREDALVINEFRAMEWORKVERSION)===-1) {
console.error('Alvine framework Version '+DEFAULTS.REQUIREDALVINEFRAMEWORKVERSION+' required, '+Alvine.getVersion()+' is given.');
}
/**
* Zuweisen in den Namespace
*/
Alvine.assignToNamespace(NAMESPACE, Example);
/**
* Hilfsfunktion und öffentliche API-Funktion zum
* Erstellen des Plugin-Objektes
*
* @param {type} options
*
* @returns {test-templateL#10.Example}
*/
function Example(options) {
return new InternalPlugin(options);
}
/**
* Beispiel einer öffentlichen Funktion zum Erstellen von Objekten
*/
function InternalPlugin() {
/**
* Überprüfen, ob diese Funktion als Konstruktor aufgerufen wurde.
* Alvine.Component.Plugin() würde zu einem Fehler führen.
* Nur der Aufruf e = new Alvine.Component.Plugin()
* funktioniert und liefert ein Objekt zurück.
*/
Alvine.Types.testIsCalledAsConstructor.call(this, 'Plugin', NAMESPACE);
/**
* Data-Objekt
*/
this.data = {};
/**
* Einfache Eigenschaft
*/
this.myPlainProperty = 37;
/**
* Eigenschaft mit erweiterten Meta-Daten.
* Detail @link https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
*/
Object.defineProperty(this, 'myExtendedValue', {
value: 37,
writable: true,
enumerable: true,
configurable: true
});
}
InternalPlugin.prototype = new Alvine.jQuery.Plugin();
// Expliziter Konstruktor für das Clonen von Objekten notwendig
InternalPlugin.prototype.constructor = InternalPlugin;
/**
* Standardwerte des Plugins
*/
InternalPlugin.prototype.getDefaults = function() {
return {
// key: 'value'
};
};
/**
* Öffentliche Funktion, die von außen über
* das Objekt aufrufbar ist
*
* e = new Plugin();
* e.doSomthing();
*
* @returns {undefined}
*/
InternalPlugin.doSomething = function() {
privatePlugin();
};
/**
* Private Funktion, die nur im Scope dieser
* Komponente sichtbar ist.
*
* @returns {undefined}
*/
function privatePlugin() {
}
} catch(e) {
Alvine.Util.Logger.logError(NAMESPACE+" "+PLUGINNAME, e);
}
})(window===undefined?window:this);