diff options
Diffstat (limited to 'lib/scripts')
-rw-r--r-- | lib/scripts/helpers.js | 278 | ||||
-rw-r--r-- | lib/scripts/media.js | 21 |
2 files changed, 166 insertions, 133 deletions
diff --git a/lib/scripts/helpers.js b/lib/scripts/helpers.js index 7b500c226..8d4f3ea78 100644 --- a/lib/scripts/helpers.js +++ b/lib/scripts/helpers.js @@ -1,132 +1,146 @@ -/**
- * $Id: helpers.js 156 2006-12-23 08:48:25Z wingedfox $
- * $HeadURL: https://svn.debugger.ru/repos/jslibs/BrowserExtensions/trunk/helpers.js $
- *
- * File contains differrent helper functions
- *
- * @author Ilya Lebedev <ilya@lebedev.net>
- * @license LGPL
- * @version $Rev: 156 $
- */
-//-----------------------------------------------------------------------------
-// Variable/property checks
-//-----------------------------------------------------------------------------
-/**
- * Checks if property is undefined
- *
- * @param {Object} prop value to check
- * @return {Boolean} true if matched
- * @scope public
- */
-function isUndefined (prop /* :Object */) /* :Boolean */ {
- return (typeof prop == 'undefined');
-}
-/**
- * Checks if property is function
- *
- * @param {Object} prop value to check
- * @return {Boolean} true if matched
- * @scope public
- */
-function isFunction (prop /* :Object */) /* :Boolean */ {
- return (typeof prop == 'function');
-}
-/**
- * Checks if property is string
- *
- * @param {Object} prop value to check
- * @return {Boolean} true if matched
- * @scope public
- */
-function isString (prop /* :Object */) /* :Boolean */ {
- return (typeof prop == 'string');
-}
-/**
- * Checks if property is number
- *
- * @param {Object} prop value to check
- * @return {Boolean} true if matched
- * @scope public
- */
-function isNumber (prop /* :Object */) /* :Boolean */ {
- return (typeof prop == 'number');
-}
-/**
- * Checks if property is the calculable number
- *
- * @param {Object} prop value to check
- * @return {Boolean} true if matched
- * @scope public
- */
-function isNumeric (prop /* :Object */) /* :Boolean */ {
- return isNumber(prop)&&!isNaN(prop)&&isFinite(prop);
-}
-/**
- * Checks if property is array
- *
- * @param {Object} prop value to check
- * @return {Boolean} true if matched
- * @scope public
- */
-function isArray (prop /* :Object */) /* :Boolean */ {
- return (prop instanceof Array);
-}
-/**
- * Checks if property is regexp
- *
- * @param {Object} prop value to check
- * @return {Boolean} true if matched
- * @scope public
- */
-function isRegExp (prop /* :Object */) /* :Boolean */ {
- return (prop instanceof RegExp);
-}
-/**
- * Checks if property is a boolean value
- *
- * @param {Object} prop value to check
- * @return {Boolean} true if matched
- * @scope public
- */
-function isBoolean (prop /* :Object */) /* :Boolean */ {
- return ('boolean' == typeof prop);
-}
-/**
- * Checks if property is a scalar value (value that could be used as the hash key)
- *
- * @param {Object} prop value to check
- * @return {Boolean} true if matched
- * @scope public
- */
-function isScalar (prop /* :Object */) /* :Boolean */ {
- return isNumeric(prop)||isString(prop);
-}
-/**
- * Checks if property is empty
- *
- * @param {Object} prop value to check
- * @return {Boolean} true if matched
- * @scope public
- */
-function isEmpty (prop /* :Object */) /* :Boolean */ {
- if (isBoolean(prop)) return false;
- if (isRegExp(prop) && new RegExp("").toString() == prop.toString()) return true;
- if (isString(prop) || isNumber(prop)) return !prop;
- if (Boolean(prop)&&false != prop) {
- for (var i in prop) if(prop.hasOwnProperty(i)) return false
- }
- return true;
-}
-
-/*
-* Checks if property is derived from prototype, applies method if it is not exists
-*
-* @param string property name
-* @return bool true if prototyped
-* @access public
-*/
-if ('undefined' == typeof Object.hasOwnProperty) {
- Object.prototype.hasOwnProperty = function (prop) {
- return !('undefined' == typeof this[prop] || this.constructor && this.constructor.prototype[prop] && this[prop] === this.constructor.prototype[prop]);
- }
-}
+/** + * Differrent helper functions + * + * @author Ilya Lebedev <ilya@lebedev.net> + * @license LGPL + */ +//----------------------------------------------------------------------------- +// Variable/property checks +//----------------------------------------------------------------------------- +/** + * Checks if property is undefined + * + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + */ +function isUndefined (prop /* :Object */) /* :Boolean */ { + return (typeof prop == 'undefined'); +} +/** + * Checks if property is function + * + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + */ +function isFunction (prop /* :Object */) /* :Boolean */ { + return (typeof prop == 'function'); +} +/** + * Checks if property is string + * + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + */ +function isString (prop /* :Object */) /* :Boolean */ { + return (typeof prop == 'string'); +} +/** + * Checks if property is number + * + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + */ +function isNumber (prop /* :Object */) /* :Boolean */ { + return (typeof prop == 'number'); +} +/** + * Checks if property is the calculable number + * + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + */ +function isNumeric (prop /* :Object */) /* :Boolean */ { + return isNumber(prop)&&!isNaN(prop)&&isFinite(prop); +} +/** + * Checks if property is array + * + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + */ +function isArray (prop /* :Object */) /* :Boolean */ { + return (prop instanceof Array); +} +/** + * Checks if property is regexp + * + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + */ +function isRegExp (prop /* :Object */) /* :Boolean */ { + return (prop instanceof RegExp); +} +/** + * Checks if property is a boolean value + * + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + */ +function isBoolean (prop /* :Object */) /* :Boolean */ { + return ('boolean' == typeof prop); +} +/** + * Checks if property is a scalar value (value that could be used as the hash key) + * + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + */ +function isScalar (prop /* :Object */) /* :Boolean */ { + return isNumeric(prop)||isString(prop); +} +/** + * Checks if property is empty + * + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + */ +function isEmpty (prop /* :Object */) /* :Boolean */ { + if (isBoolean(prop)) return false; + if (isRegExp(prop) && new RegExp("").toString() == prop.toString()) return true; + if (isString(prop) || isNumber(prop)) return !prop; + if (Boolean(prop)&&false != prop) { + for (var i in prop) if(prop.hasOwnProperty(i)) return false + } + return true; +} + +/** + * Checks if property is derived from prototype, applies method if it is not exists + * + * @param string property name + * @return bool true if prototyped + * @access public + */ +if ('undefined' == typeof Object.hasOwnProperty) { + Object.prototype.hasOwnProperty = function (prop) { + return !('undefined' == typeof this[prop] || this.constructor && this.constructor.prototype[prop] && this[prop] === this.constructor.prototype[prop]); + } +} + +/** + * Very simplistic Flash plugin check, probably works for Flash 8 and higher only + */ +function hasFlash(version){ + var ver = 0; + try{ + if(navigator.plugins != null && navigator.plugins.length > 0){ + ver = navigator.plugins["Shockwave Flash"].description.split(' ')[2].split('.')[0]; + }else{ + var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); + ver = axo.GetVariable("$version").split(' ')[1].split(',')[0]; + } + }catch(e){ } + + if(ver >= version) return true; + return false; +} diff --git a/lib/scripts/media.js b/lib/scripts/media.js index f616f8741..ebfd01322 100644 --- a/lib/scripts/media.js +++ b/lib/scripts/media.js @@ -265,12 +265,31 @@ media = { text = text.substr(text.lastIndexOf('/')+1); text = text.substr(text.lastIndexOf('\\')+1); name.value = text; - } + }, + + initFlashUpload: function(){ + if(!hasFlash(8)) return; + var oform = $('dw__upload'); + var oflash = $('dw__flashupload'); + if(!oform || !oflash) return; + + var clicky = document.createElement('img'); + clicky.src = DOKU_BASE+'lib/images/multiupload.png'; + clicky.title = LANG['mu_btn']; + clicky.alt = LANG['mu_btn']; + clicky.style.cursor = 'pointer'; + clicky.onclick = function(){ + oform.style.display = 'none'; + oflash.style.display = ''; + }; + oform.appendChild(clicky); + } }; addInitEvent(function(){ media.treeattach($('media__tree')); media.selectorattach($('media__content')); media.attachoptions($('media__opts')); + media.initFlashUpload(); }); |