some improvements for menu and select

This commit is contained in:
Rolux 2010-02-06 15:59:27 +05:30
parent ec1693c2c4
commit 4cc7bad63c
2 changed files with 29 additions and 23 deletions

View file

@ -80,7 +80,7 @@ Ox.user = function() {
var result = re(v); var result = re(v);
results[result[1].replace(/Your |\*/, "")] = result[2]; results[result[1].replace(/Your |\*/, "")] = result[2];
}); });
console.log(results) Ox.print(results)
}); });
return { return {
document: { document: {
@ -815,7 +815,7 @@ Encoding functions
} }
c.context.putImageData(c.imageData, 0, 0); c.context.putImageData(c.imageData, 0, 0);
data = atob(c.canvas.toDataURL().split(",")[1]); data = atob(c.canvas.toDataURL().split(",")[1]);
console.log("deflate", len, "->", data.length - 20); Ox.print("deflate", len, "->", data.length - 20);
return data.substr(8, data.length - 20); return data.substr(8, data.length - 20);
} }
@ -827,7 +827,7 @@ Encoding functions
str = Ox.map(Ox.canvas(image).data, function(v, i) { str = Ox.map(Ox.canvas(image).data, function(v, i) {
return i % 4 < 3 ? Ox.char(v) : ""; return i % 4 < 3 ? Ox.char(v) : "";
}).join(""); }).join("");
//console.log(str.length, "len", Ox.decodeBase256(str.substr(0, 4)), str) //Ox.print(str.length, "len", Ox.decodeBase256(str.substr(0, 4)), str)
return Ox.decodeUTF8(str.substr(4, Ox.decodeBase256(str.substr(0, 4)))); return Ox.decodeUTF8(str.substr(4, Ox.decodeBase256(str.substr(0, 4))));
} }
@ -916,7 +916,7 @@ Encoding functions
if (len == 0 && !flag) { if (len == 0 && !flag) {
len = Ox.decodeBase256(str); len = Ox.decodeBase256(str);
if (len <= 0 || len > max(img.width, img.height)) { if (len <= 0 || len > max(img.width, img.height)) {
console.log(len); Ox.print(len);
throwPNGError("de"); throwPNGError("de");
} }
str = ""; str = "";
@ -927,7 +927,7 @@ Encoding functions
try { try {
return Ox.decodeDeflate(str); return Ox.decodeDeflate(str);
} catch(e) { } catch(e) {
console.log(e.toString()); Ox.print(e.toString());
throwPNGError("de"); throwPNGError("de");
} }
} }

View file

@ -254,7 +254,7 @@ requires
return { return {
// make these bind, trigger, unbind // make these bind, trigger, unbind
publish: function(event, data) { publish: function(event, data) {
console.log("publish", event, data); Ox.print("publish", event, data);
if (events[event]) { if (events[event]) {
$.each(events[event], function(i, v) { $.each(events[event], function(i, v) {
setTimeout(function() { setTimeout(function() {
@ -264,7 +264,7 @@ requires
} }
}, },
subscribe: function(event, callback) { subscribe: function(event, callback) {
console.log("subscribe", event, callback); Ox.print("subscribe", event, callback);
if (events[event]) { if (events[event]) {
events[event].push(callback); events[event].push(callback);
} else { } else {
@ -272,7 +272,7 @@ requires
} }
}, },
unsubscribe: function(event, callback) { unsubscribe: function(event, callback) {
console.log("unsubscribe", event, callback); Ox.print("unsubscribe", event, callback);
$.each(events[event], function(i, v) { $.each(events[event], function(i, v) {
if (Ox.startsWith(callback.toString(), v.toString())) { if (Ox.startsWith(callback.toString(), v.toString())) {
events[event].splice(i, 1); events[event].splice(i, 1);
@ -820,6 +820,8 @@ requires
// public // public
that.bindEvent = function() { that.bindEvent = function() {
// fixme: shouldn't this work the other way around,
// and bind a function to an event triggered by this widget?
/* /*
bindEvent(event, fn) or bindEvent({event0: fn0, event1: fn1, ...}) bindEvent(event, fn) or bindEvent({event0: fn0, event1: fn1, ...})
*/ */
@ -940,12 +942,12 @@ requires
that.opt = {}; that.opt = {};
that.ox = Ox.version; that.ox = Ox.version;
that.id = Ox.uid(); that.id = Ox.uid();
//console.log("that.id", that.id) //Ox.print("that.id", that.id)
that.$element = $("<" + (element || "div") + "/>") that.$element = $("<" + (element || "div") + "/>")
//.addClass("OxElement") //.addClass("OxElement")
.data("ox", that.id); .data("ox", that.id);
oxui.elements[that.id] = that; oxui.elements[that.id] = that;
// console.log("oxui.elements", oxui.elements) // Ox.print("oxui.elements", oxui.elements)
//function setOption() {}; //function setOption() {};
that.setOption = function() {}; that.setOption = function() {};
/* /*
@ -999,10 +1001,10 @@ requires
var length = arguments.length, var length = arguments.length,
args, ret; args, ret;
if (length == 0) { if (length == 0) {
//console.log("getting all options", options); //Ox.print("getting all options", options);
ret = that.opt; ret = that.opt;
} else if (length == 1 && typeof arguments[0] == "string") { } else if (length == 1 && typeof arguments[0] == "string") {
//console.log("getting one option", options, arguments[0], options[arguments[0]]); //Ox.print("getting one option", options, arguments[0], options[arguments[0]]);
ret = that.opt[arguments[0]]; ret = that.opt[arguments[0]];
} else { } else {
// translate ("key", "value") to {"key": "value"} // translate ("key", "value") to {"key": "value"}
@ -1014,7 +1016,7 @@ requires
// that.trigger("OxElement" + that.id + "SetOptions", args); // that.trigger("OxElement" + that.id + "SetOptions", args);
$.each(args, function(k, v) { $.each(args, function(k, v) {
that.setOption(k, v); that.setOption(k, v);
//console.log("triggering", "OxElement" + that.id + "SetOption", {k: v}) //Ox.print("triggering", "OxElement" + that.id + "SetOption", {k: v})
//that.trigger("OxElement" + that.id + "SetOption", {k: v}); //that.trigger("OxElement" + that.id + "SetOption", {k: v});
}) })
ret = that; ret = that;
@ -1071,9 +1073,9 @@ requires
// if the $element of an oxui object was returned // if the $element of an oxui object was returned
// then return the oxui object instead // then return the oxui object instead
// so we can do oxObj.jqFn().oxFn() // so we can do oxObj.jqFn().oxFn()
//console.log("v", v, "arguments", arguments) //Ox.print("v", v, "arguments", arguments)
if (ret.jquery) { if (ret.jquery) {
//console.log("ret", ret, "ret.data('id')", ret.data("ox")) //Ox.print("ret", ret, "ret.data('id')", ret.data("ox"))
} }
return ret.jquery && oxui.elements[id = ret.data("ox")] ? return ret.jquery && oxui.elements[id = ret.data("ox")] ?
oxui.elements[id] : ret; oxui.elements[id] : ret;
@ -1334,7 +1336,7 @@ requires
(self.options.selected ? " OxSelected": "")) (self.options.selected ? " OxSelected": ""))
.mousedown(mousedown) .mousedown(mousedown)
.click(click); .click(click);
//console.log(self.options.value, self.options.disabled) //Ox.print(self.options.value, self.options.disabled)
/* /*
that.bind("OxElement" + that.id + "SetOptions", function(e, data) { that.bind("OxElement" + that.id + "SetOptions", function(e, data) {
if (typeof data.selected != "undefined") { if (typeof data.selected != "undefined") {
@ -1366,7 +1368,7 @@ requires
} }
Ox.print(self.options); Ox.print(self.options);
if (self.options.values.length == 2) { if (self.options.values.length == 2) {
console.log("2 values") Ox.print("2 values")
that.options({ that.options({
value: self.options.value == self.options.values[0] ? value: self.options.value == self.options.values[0] ?
self.options.values[1] : self.options.values[0] self.options.values[1] : self.options.values[0]
@ -1375,7 +1377,7 @@ requires
//self.options.click(); //self.options.click();
} }
self.onChange = function(key, value) { self.onChange = function(key, value) {
//console.log("setOption", option, value) //Ox.print("setOption", option, value)
Ox.print("OxButton onChange", key, value) Ox.print("OxButton onChange", key, value)
if (key == "selected") { if (key == "selected") {
if (value != that.hasClass("OxSelected")) { if (value != that.hasClass("OxSelected")) {
@ -1485,20 +1487,20 @@ requires
.blur(blur); .blur(blur);
/* doesn't work yet /* doesn't work yet
function change() { function change() {
console.log("change", that.val(), that.hasClass("OxPlaceholder")) Ox.print("change", that.val(), that.hasClass("OxPlaceholder"))
if ((that.val() !== "") != that.hasClass("OxPlaceholder")) { if ((that.val() !== "") != that.hasClass("OxPlaceholder")) {
that.toggleClass("OxPlaceholder"); that.toggleClass("OxPlaceholder");
} }
} }
*/ */
function focus() { function focus() {
console.log("focus", that.val(), that.attr("class")) Ox.print("focus", that.val(), that.attr("class"))
if (that.hasClass("OxPlaceholder")) { if (that.hasClass("OxPlaceholder")) {
that.val("").removeClass("OxPlaceholder"); that.val("").removeClass("OxPlaceholder");
} }
} }
function blur() { function blur() {
console.log("blur", that.val(), that.attr("class")) Ox.print("blur", that.val(), that.attr("class"))
if (that.val() === "") { if (that.val() === "") {
that.addClass("OxPlaceholder").val(that.attr("placeholder")); that.addClass("OxPlaceholder").val(that.attr("placeholder"));
} }
@ -1598,7 +1600,7 @@ requires
c = $image[0].getContext('2d'); c = $image[0].getContext('2d');
c.mozImageSmoothingEnabled = false; // we may want to remove this later c.mozImageSmoothingEnabled = false; // we may want to remove this later
$.each(self.options.trackImages, function(i, v) { $.each(self.options.trackImages, function(i, v) {
//console.log(v) //Ox.print(v)
$("<img/>") $("<img/>")
.attr({ .attr({
src: v src: v
@ -1689,7 +1691,7 @@ requires
value: val value: val
}); });
setThumb(animate); setThumb(animate);
//console.log("triggering OxRange" + that.id + "Change") //Ox.print("triggering OxRange" + that.id + "Change")
that.triggerEvent("change", { value: val }); that.triggerEvent("change", { value: val });
} }
} }
@ -1776,6 +1778,10 @@ requires
element: that.$button, element: that.$button,
id: self.options.id, id: self.options.id,
items: self.options.items, items: self.options.items,
offset: {
left: 8,
top: 0
},
side: "bottom", side: "bottom",
size: self.options.size size: self.options.size
}); });