summaryrefslogtreecommitdiffstats
path: root/pyload/web/app/scripts/utils
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/web/app/scripts/utils')
-rw-r--r--pyload/web/app/scripts/utils/animations.js129
-rw-r--r--pyload/web/app/scripts/utils/apitypes.js16
-rw-r--r--pyload/web/app/scripts/utils/dialogs.js15
-rw-r--r--pyload/web/app/scripts/utils/i18n.js5
-rw-r--r--pyload/web/app/scripts/utils/lazyRequire.js97
5 files changed, 262 insertions, 0 deletions
diff --git a/pyload/web/app/scripts/utils/animations.js b/pyload/web/app/scripts/utils/animations.js
new file mode 100644
index 000000000..7f89afef1
--- /dev/null
+++ b/pyload/web/app/scripts/utils/animations.js
@@ -0,0 +1,129 @@
+define(['jquery', 'underscore', 'transit'], function(jQuery, _) {
+ 'use strict';
+
+ // Adds an element and computes its height, which is saved as data attribute
+ // Important function to have slide animations
+ jQuery.fn.appendWithHeight = function(element, hide) {
+ var o = jQuery(this[0]);
+ element = jQuery(element);
+
+ // TODO: additionally it could be placed out of viewport first
+ // The real height can only be retrieved when element is on DOM and display:true
+ element.css('visibility', 'hidden');
+ o.append(element);
+
+ var height = element.height();
+
+ // Hide the element
+ if (hide === true) {
+ element.hide();
+ element.height(0);
+ }
+
+ element.css('visibility', '');
+ element.data('height', height);
+
+ return this;
+ };
+
+ // Shortcut to have a animation when element is added
+ jQuery.fn.appendWithAnimation = function(element, animation) {
+ var o = jQuery(this[0]);
+ element = jQuery(element);
+
+ if (animation === true)
+ element.hide();
+
+ o.append(element);
+
+ if (animation === true)
+ element.fadeIn();
+
+// element.calculateHeight();
+
+ return this;
+ };
+
+ // calculate the height and write it to data, should be used on invisible elements
+ jQuery.fn.calculateHeight = function(setHeight) {
+ var o = jQuery(this[0]);
+ var height = o.height();
+ if (!height) {
+ var display = o.css('display');
+ o.css('visibility', 'hidden');
+ o.show();
+ height = o.height();
+
+ o.css('display', display);
+ o.css('visibility', '');
+ }
+
+ if (setHeight)
+ o.css('height', height);
+
+ o.data('height', height);
+ return this;
+ };
+
+ // TODO: carry arguments, optional height argument
+
+ // reset arguments, sets overflow hidden
+ jQuery.fn.slideOut = function(reset) {
+ var o = jQuery(this[0]);
+ o.animate({height: o.data('height'), opacity: 'show'}, function() {
+ // reset css attributes;
+ if (reset) {
+ this.css('overflow', '');
+ this.css('height', '');
+ }
+ });
+ return this;
+ };
+
+ jQuery.fn.slideIn = function(reset) {
+ var o = jQuery(this[0]);
+ if (reset) {
+ o.css('overflow', 'hidden');
+ }
+ o.animate({height: 0, opacity: 'hide'});
+ return this;
+ };
+
+ jQuery.fn.initTooltips = function(placement) {
+ placement || (placement = 'top');
+
+ var o = jQuery(this[0]);
+ o.find('[data-toggle="tooltip"]').tooltip(
+ {
+ delay: {show: 800, hide: 100},
+ placement: placement
+ });
+
+ return this;
+ };
+
+ jQuery.fn._transit = jQuery.fn.transit;
+
+ // Overriding transit plugin to support hide and show
+ jQuery.fn.transit = jQuery.fn.transition = function(props, duration, easing, callback) {
+ var self = this;
+ var cb = callback;
+ var newprops = _.extend({}, props);
+
+ if (newprops && (newprops.opacity === 'hide')) {
+ newprops.opacity = 0;
+
+ callback = function() {
+ self.css({display: 'none'});
+ if (typeof cb === 'function') {
+ cb.apply(self);
+ }
+ };
+ } else if (newprops && (newprops.opacity === 'show')) {
+ newprops.opacity = 1;
+ this.css({display: 'block'});
+ }
+
+ return this._transit(newprops, duration, easing, callback);
+ };
+}); \ No newline at end of file
diff --git a/pyload/web/app/scripts/utils/apitypes.js b/pyload/web/app/scripts/utils/apitypes.js
new file mode 100644
index 000000000..cb094a05b
--- /dev/null
+++ b/pyload/web/app/scripts/utils/apitypes.js
@@ -0,0 +1,16 @@
+// Autogenerated, do not edit!
+/*jslint -W070: false*/
+define([], function() {
+ 'use strict';
+ return {
+ DownloadState: {'Failed': 3, 'All': 0, 'Unmanaged': 4, 'Finished': 1, 'Unfinished': 2},
+ DownloadStatus: {'NotPossible': 13, 'Downloading': 10, 'NA': 0, 'Processing': 15, 'Waiting': 9, 'Decrypting': 14, 'Paused': 4, 'Failed': 7, 'Finished': 5, 'Skipped': 6, 'Unknown': 17, 'Aborted': 12, 'Online': 2, 'TempOffline': 11, 'Offline': 1, 'Custom': 16, 'Starting': 8, 'Queued': 3},
+ FileStatus: {'Remote': 2, 'Ok': 0, 'Missing': 1},
+ InputType: {'PluginList': 13, 'Multiple': 11, 'Int': 2, 'NA': 0, 'Time': 7, 'List': 12, 'Bool': 8, 'File': 3, 'Text': 1, 'Table': 14, 'Folder': 4, 'Password': 6, 'Click': 9, 'Select': 10, 'Textbox': 5},
+ Interaction: {'Captcha': 2, 'All': 0, 'Query': 4, 'Notification': 1},
+ MediaType: {'All': 0, 'Audio': 2, 'Image': 4, 'Executable': 64, 'Other': 1, 'Video': 8, 'Document': 16, 'Archive': 32},
+ PackageStatus: {'Paused': 1, 'Remote': 3, 'Folder': 2, 'Ok': 0},
+ Permission: {'All': 0, 'Interaction': 32, 'Modify': 4, 'Add': 1, 'Accounts': 16, 'Plugins': 64, 'Download': 8, 'Delete': 2},
+ Role: {'Admin': 0, 'User': 1},
+ };
+}); \ No newline at end of file
diff --git a/pyload/web/app/scripts/utils/dialogs.js b/pyload/web/app/scripts/utils/dialogs.js
new file mode 100644
index 000000000..3ceffc9c3
--- /dev/null
+++ b/pyload/web/app/scripts/utils/dialogs.js
@@ -0,0 +1,15 @@
+// Loads all helper and set own handlebars rules
+define(['jquery', 'underscore', 'views/abstract/modalView'], function($, _, Modal) {
+ 'use strict';
+
+ // Shows the confirm dialog for given context
+ // on success executes func with context
+ _.confirm = function(template, func, context) {
+ template = 'hbs!tpl/' + template;
+ _.requireOnce([template], function(html) {
+ var dialog = new Modal(html, _.bind(func, context));
+ dialog.show();
+ });
+
+ };
+}); \ No newline at end of file
diff --git a/pyload/web/app/scripts/utils/i18n.js b/pyload/web/app/scripts/utils/i18n.js
new file mode 100644
index 000000000..a8d948b4a
--- /dev/null
+++ b/pyload/web/app/scripts/utils/i18n.js
@@ -0,0 +1,5 @@
+define(['jed'], function(Jed) {
+ 'use strict';
+ // TODO load i18n data
+ return new Jed({});
+}); \ No newline at end of file
diff --git a/pyload/web/app/scripts/utils/lazyRequire.js b/pyload/web/app/scripts/utils/lazyRequire.js
new file mode 100644
index 000000000..96c07aa24
--- /dev/null
+++ b/pyload/web/app/scripts/utils/lazyRequire.js
@@ -0,0 +1,97 @@
+// Define the module.
+define(
+ [
+ 'require', 'underscore'
+ ],
+ function( require, _ ){
+ 'use strict';
+
+
+ // Define the states of loading for a given set of modules
+ // within a require() statement.
+ var states = {
+ unloaded: 'UNLOADED',
+ loading: 'LOADING',
+ loaded: 'LOADED'
+ };
+
+
+ // Define the top-level module container. Mostly, we're making
+ // the top-level container a non-Function so that users won't
+ // try to invoke this without calling the once() method below.
+ var lazyRequire = {};
+
+
+ // I will return a new, unique instance of the requrieOnce()
+ // method. Each instance will only call the require() method
+ // once internally.
+ lazyRequire.once = function(){
+
+ // The modules start in an unloaded state before
+ // requireOnce() is invoked by the calling code.
+ var state = states.unloaded;
+ var args;
+
+ var requireOnce = function(dependencies, loadCallback ){
+
+ // Use the module state to determine which method to
+ // invoke (or just to ignore the invocation).
+ if (state === states.loaded){
+ loadCallback.apply(null, args);
+
+ // The modules have not yet been requested - let's
+ // lazy load them.
+ } else if (state !== states.loading){
+
+ // We're about to load the modules asynchronously;
+ // flag the interim state.
+ state = states.loading;
+
+ // Load the modules.
+ require(
+ dependencies,
+ function(){
+
+ args = arguments;
+ loadCallback.apply( null, args );
+ state = states.loaded;
+
+
+ }
+ );
+
+ // RequireJS is currently loading the modules
+ // asynchronously, but they have not finished
+ // loading yet.
+ } else {
+
+ // Simply ignore this call.
+ return;
+
+ }
+
+ };
+
+ // Return the new lazy loader.
+ return( requireOnce );
+
+ };
+
+
+ // -------------------------------------------------- //
+ // -------------------------------------------------- //
+
+ // Set up holder for underscore
+ var instances = {};
+ _.requireOnce = function(dependencies, loadCallback) {
+ if (!_.has(instances, dependencies))
+ instances[dependencies] = lazyRequire.once();
+
+ return instances[dependencies](dependencies, loadCallback);
+ };
+
+
+ // Return the module definition.
+ return( lazyRequire );
+ }
+); \ No newline at end of file