From 53d4d2ecc916a800c7c0c745ffc1306daac34379 Mon Sep 17 00:00:00 2001 From: Donna Wu Date: Thu, 28 Jun 2012 11:26:46 +0800 Subject: [PATCH 1/5] [FileIO] Enable image upload feature in property view --- src/js/views/property.js | 20 ++++++++++++++++++++ src/js/widgets.js | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/js/views/property.js b/src/js/views/property.js index 6be0924a..d3c62872 100644 --- a/src/js/views/property.js +++ b/src/js/views/property.js @@ -160,6 +160,26 @@ value.find("#" + valueId).attr("checked", "checked"); } break; + case "url-uploadable": + $('') + .attr('id', valueId) + .addClass('title labelInput') + .appendTo(value); + //set default value + value.find('#' + valueId).val(valueVal); + $('') + .addClass('buttonStyle') + .click(function (e) { + var target, saveDir; + target = $(this).prev("input:text"); + saveDir = $.rib.pmUtils.ProjectDir + "/" + $.rib.pmUtils.getActive() + "/images/"; + $.rib.fsUtils.uploadAndSave("image", saveDir, $(this).parent(), function (file) { + target.val(file.toURL()); + target.trigger('change'); + }); + }) + .appendTo(value); + break; case "record-array": $('') .attr('id', 'selectOption') diff --git a/src/js/widgets.js b/src/js/widgets.js index 97a4b161..5408e1ab 100644 --- a/src/js/widgets.js +++ b/src/js/widgets.js @@ -216,7 +216,7 @@ var BWidgetRegistry = { parent: "Base", properties: { background: { - type: "string", + type: "url-uploadable", defaultValue: "", htmlAttribute: { name: "style", @@ -660,7 +660,7 @@ var BWidgetRegistry = { template: '', properties: { src: { - type: "string", + type: "url-uploadable", defaultValue: "src/css/images/widgets/tizen_image.svg", htmlAttribute: "src", forceAttribute: true From 9375f1bc751448dc58fad54644dfee33fe3d7c60 Mon Sep 17 00:00:00 2001 From: Donna Wu Date: Thu, 28 Jun 2012 14:27:21 +0800 Subject: [PATCH 2/5] [FileIO] Fix bug: upload dialog can not show on lower version Chrome --- src/js/fs.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js/fs.js b/src/js/fs.js index 4350ba4e..e3af3659 100644 --- a/src/js/fs.js +++ b/src/js/fs.js @@ -527,7 +527,9 @@ $(function() { // remove the temp input element input.remove(); }); - input.click(); + setTimeout(function() { + input.click(); + }, 0); }, /** From 7588e23d81e503d6711a98a52fa37b490cb77c18 Mon Sep 17 00:00:00 2001 From: John Chen Date: Thu, 28 Jun 2012 14:43:02 +0800 Subject: [PATCH 3/5] [Widgets] enhence jquery.extend to support array replacement --- src/js/jquery-workarounds.js | 100 +++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/src/js/jquery-workarounds.js b/src/js/jquery-workarounds.js index 16d08e90..b8b7b9b1 100644 --- a/src/js/jquery-workarounds.js +++ b/src/js/jquery-workarounds.js @@ -342,3 +342,103 @@ $.widget("ui.droppable", $.extend({}, $.ui.droppable.prototype, { } })); + +/* + * This is an enhencement for jquery.extend, which tries to extend + * an array field just like an object while deep extending and in some + * case produces unexpected reuslt. For example, [0, 1, 2] extends by + * [3] results in [3, 1, 2] instead of [3]. + * See http://bugs.jquery.com/ticket/9477 for more details about this + * issue. + * + * We override jquery.extend function so that a flag can be specified + * to indicate whether arrays should be replaced or not. + * + * Copied from jquery version 1.6.4, jquery-1.6.4.js + */ +jQuery.extend = jQuery.fn.extend = function() { + var options, name, src, copy, copyIsArray, clone, + target = arguments[0] || {}, + i = 1, + length = arguments.length, + replaceArray = false; + deep = false; + + // Handle a deep copy situation + if ( typeof target === "boolean" ) { + deep = target; + target = arguments[1] || {}; + // skip the boolean and the target + i = 2; + } + + ///////////////////////////////////////////////////////////////// + // Start of our changes + // Introduce a new argument to specifiy if we need to replace + // an array when encountered. + if ( typeof target === "boolean" ) { + replaceArray = target; + target = arguments[2] || {}; + // skip the boolean and the target + i = 3; + } + ///////////////////////////////////////////////////////////////// + // End of our changes + + // Handle case when target is a string or something (possible in deep copy) + if ( typeof target !== "object" && !jQuery.isFunction(target) ) { + target = {}; + } + + // extend jQuery itself if only one argument is passed + if ( length === i ) { + target = this; + --i; + } + + for ( ; i < length; i++ ) { + // Only deal with non-null/undefined values + if ( (options = arguments[ i ]) != null ) { + // Extend the base object + for ( name in options ) { + src = target[ name ]; + copy = options[ name ]; + + // Prevent never-ending loop + if ( target === copy ) { + continue; + } + + // Recurse if we're merging plain objects or arrays + if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) { + if ( copyIsArray ) { + copyIsArray = false; + ///////////////////////////////////////////////////////////////// + // Start of our changes + // If replaceArray is true, we uses an empty array as clone so + // the whole array will be replaced by copy + // Following is the original line: + // clone = src && jQuery.isArray(src) ? src : []; + clone = src && jQuery.isArray(src) && !replaceArray ? src : []; + ///////////////////////////////////////////////////////////////// + // End of our changes + + } else { + clone = src && jQuery.isPlainObject(src) ? src : {}; + } + + // Never move original objects, clone them + target[ name ] = jQuery.extend( deep, clone, copy ); + + // Don't bring in undefined values + } else if ( copy !== undefined ) { + target[ name ] = copy; + } + } + } + } + + // Return the modified object + return target; +}; + From ac086048c6feedc5fd0af0af4fc4de12b0be851b Mon Sep 17 00:00:00 2001 From: John Chen Date: Tue, 19 Jun 2012 17:53:11 +0800 Subject: [PATCH 4/5] [Widgets] Deeply extend widget Currently only properties are inherited when extending a widget, this patch also extend other defintions of a wdiget. Be cautious that all elements of an array should be specified in the child type if you don't want to override them. --- src/js/widgets.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/js/widgets.js b/src/js/widgets.js index 97a4b161..81931d5f 100644 --- a/src/js/widgets.js +++ b/src/js/widgets.js @@ -113,7 +113,6 @@ var BWidgetRegistry = { */ Base: { parent: null, - allowIn: [], applyProperties: function (node, code) { var id = node.getProperty("id"); if (id && node.isPropertyExplicit("id")) { @@ -121,9 +120,8 @@ var BWidgetRegistry = { } return code; }, - showInPalette: false, - selectable: false, - moveable: false, + selectable: true, + moveable: true, properties: { id: { type: "string", @@ -2053,7 +2051,7 @@ var BWidget = { init: function () { // effects: add the type and displayLabel properties to widget // registry objects - var type; + var type, parentName; for (type in BWidgetRegistry) { if (BWidgetRegistry.hasOwnProperty(type)) { BWidgetRegistry[type].type = type; @@ -2089,6 +2087,11 @@ var BWidget = { if (type === "OptionHeader") { BWidgetRegistry[type].displayLabel = "Option Header"; } + parentName = BWidgetRegistry[type].parent; + while (parentName) { + BWidgetRegistry[type] = $.extend(true, true, {}, BWidgetRegistry[parentName], BWidgetRegistry[type]); + parentName = BWidgetRegistry[parentName].parent; + } } } }, From e0002e2d6e47101f1f2e861154ce111b730363bc Mon Sep 17 00:00:00 2001 From: John Chen Date: Thu, 28 Jun 2012 16:55:48 +0800 Subject: [PATCH 5/5] [Widgets] Remove unnecessary hierachy handling code As each widget has all the fields extended with base widget, we don't have to build hierachy when getting property fields --- src/js/widgets.js | 74 +++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 54 deletions(-) diff --git a/src/js/widgets.js b/src/js/widgets.js index 81931d5f..19e5cca3 100644 --- a/src/js/widgets.js +++ b/src/js/widgets.js @@ -2249,26 +2249,17 @@ var BWidget = { * @throws {Error} If widgetType is invalid. */ getPropertyTypes: function (widgetType) { - var stack = [], props = {}, length, i, property, widget, currentWidget; - widget = currentWidget = BWidgetRegistry[widgetType]; + var stack = [], props = {}, length, i, property, widget; + widget = BWidgetRegistry[widgetType]; if (typeof widget !== "object") { throw new Error("undefined widget type in getPropertyTypes: " + widgetType); } - // build hierarchical stack so child properties will override parents - while (currentWidget) { - stack.unshift(currentWidget.properties); - currentWidget = BWidgetRegistry[currentWidget.parent]; - } - - length = stack.length; - for (i = 0; i < length; i++) { - for (property in stack[i]) { - if (stack[i].hasOwnProperty(property)) { - props[property] = stack[i][property].type; - } + for (property in widget.properties) { + if (widget.properties.hasOwnProperty(property)) { + props[property] = widget.properties[property].type; } } return props; @@ -2285,30 +2276,20 @@ var BWidget = { * @throws {Error} If widgetType is invalid. */ getPropertyOptions: function (widgetType) { - var stack = [], options = {}, length, i, property, widget, currentWidget; - widget = currentWidget = BWidgetRegistry[widgetType]; + var stack = [], options = {}, length, i, property, widget; + widget = BWidgetRegistry[widgetType]; if (typeof widget !== "object") { throw new Error("undefined widget type in getPropertyOptions: " + widgetType); } - // build hierarchical stack so child properties will override parents - // although, really there should be no such conflicts - while (currentWidget) { - stack.unshift(currentWidget.properties); - currentWidget = BWidgetRegistry[currentWidget.parent]; - } - - length = stack.length; - for (i = 0; i < length; i++) { - for (property in stack[i]) { - if (stack[i].hasOwnProperty(property)) { - options[property] = stack[i][property].options; - } + for (property in widget.properties) { + if (widget.properties.hasOwnProperty(property)) { + options[property] = widget.properties[property].options; } } - return options; + return $.extend(true, {}, options); }, /** @@ -2321,30 +2302,20 @@ var BWidget = { * @throws {Error} If widgetType is invalid. */ getPropertyDefaults: function (widgetType) { - var stack = [], props = {}, length, i, property, widget, currentWidget; - widget = currentWidget = BWidgetRegistry[widgetType]; + var stack = [], props = {}, length, i, property, widget; + widget = BWidgetRegistry[widgetType]; if (typeof widget !== "object") { throw new Error("undefined widget type in getPropertyDefaults: "+ widgetType); } - - // build hierarchical stack so child properties will override parents - // although, really there should be no such conflicts - while (currentWidget) { - stack.unshift(currentWidget.properties); - currentWidget = BWidgetRegistry[currentWidget.parent]; - } - - length = stack.length; - for (i = 0; i < length; i++) { - for (property in stack[i]) { - if (stack[i].hasOwnProperty(property)) { - props[property] = stack[i][property].defaultValue; - } + for (property in widget.properties) { + if (widget.properties.hasOwnProperty(property)) { + props[property] = widget.properties[property].defaultValue; } } - return props; + + return $.extend(true, {}, props); }, /** @@ -2363,13 +2334,8 @@ var BWidget = { widgetType); } - // build hierarchical stack so child properties will override parents - while (widget) { - if (widget.properties && widget.properties[property]) { - return widget.properties[property]; - } - widgetType = widget.parent; - widget = BWidgetRegistry[widgetType]; + if (widget.properties && widget.properties[property]) { + return $.extend(true, {}, widget.properties[property]); } // no such property found in hierarchy