Replacing OpenAjax with a jQuery solution.

--HG--
branch : dev
This commit is contained in:
Dave Reed
2011-02-16 14:55:51 -08:00
parent 8c8aed694b
commit 165644972a
10 changed files with 31 additions and 245 deletions

View File

@@ -266,7 +266,6 @@
<Content Include="Shapes\Scripts\base.js" />
<Content Include="Shapes\Scripts\html5.js" />
<Content Include="Shapes\Scripts\jquery.switchable.js" />
<Content Include="Shapes\Scripts\OpenAjax.js" />
<Content Include="Shapes\Styles\Images\detail-view-on.gif" />
<Content Include="Shapes\Styles\Images\detail-view.gif" />
<Content Include="Shapes\Styles\Images\summary-view-on.gif" />

View File

@@ -5,7 +5,6 @@ namespace Orchard.Core.Shapes {
public void BuildManifests(ResourceManifestBuilder builder) {
var manifest = builder.Add();
manifest.DefineScript("ShapesBase").SetUrl("base.js").SetDependencies("jQuery");
manifest.DefineScript("OpenAjax").SetUrl("OpenAjax.js");
manifest.DefineStyle("Shapes").SetUrl("site.css"); // todo: missing
manifest.DefineStyle("ShapesSpecial").SetUrl("special.css");

View File

@@ -1,191 +0,0 @@
/*******************************************************************************
* OpenAjax.js
*
* Reference implementation of the OpenAjax Hub, as specified by OpenAjax Alliance.
* Specification is under development at:
*
* http://www.openajax.org/member/wiki/OpenAjax_Hub_Specification
*
* Copyright 2006-2009 OpenAjax Alliance
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0 . Unless
* required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
******************************************************************************/
// prevent re-definition of the OpenAjax object
if(!window["OpenAjax"]){
OpenAjax = new function(){
var t = true;
var f = false;
var g = window;
var ooh = "org.openajax.hub.";
var h = {};
this.hub = h;
h.implementer = "http://openajax.org";
h.implVersion = "2.0";
h.specVersion = "2.0";
h.implExtraData = {};
var libs = {};
h.libraries = libs;
h.registerLibrary = function(prefix, nsURL, version, extra){
libs[prefix] = {
prefix: prefix,
namespaceURI: nsURL,
version: version,
extraData: extra
};
this.publish(ooh+"registerLibrary", libs[prefix]);
}
h.unregisterLibrary = function(prefix){
this.publish(ooh+"unregisterLibrary", libs[prefix]);
delete libs[prefix];
}
h._subscriptions = { c:{}, s:[] };
h._cleanup = [];
h._subIndex = 0;
h._pubDepth = 0;
h.subscribe = function(name, callback, scope, subscriberData, filter)
{
if(!scope){
scope = window;
}
var handle = name + "." + this._subIndex;
var sub = { scope: scope, cb: callback, fcb: filter, data: subscriberData, sid: this._subIndex++, hdl: handle };
var path = name.split(".");
this._subscribe(this._subscriptions, path, 0, sub);
return handle;
}
h.publish = function(name, message)
{
var path = name.split(".");
this._pubDepth++;
this._publish(this._subscriptions, path, 0, name, message);
this._pubDepth--;
if((this._cleanup.length > 0) && (this._pubDepth == 0)) {
for(var i = 0; i < this._cleanup.length; i++)
this.unsubscribe(this._cleanup[i].hdl);
delete(this._cleanup);
this._cleanup = [];
}
}
h.unsubscribe = function(sub)
{
var path = sub.split(".");
var sid = path.pop();
this._unsubscribe(this._subscriptions, path, 0, sid);
}
h._subscribe = function(tree, path, index, sub)
{
var token = path[index];
if(index == path.length)
tree.s.push(sub);
else {
if(typeof tree.c == "undefined")
tree.c = {};
if(typeof tree.c[token] == "undefined") {
tree.c[token] = { c: {}, s: [] };
this._subscribe(tree.c[token], path, index + 1, sub);
}
else
this._subscribe( tree.c[token], path, index + 1, sub);
}
}
h._publish = function(tree, path, index, name, msg, pid) {
if(typeof tree != "undefined") {
var node;
if(index == path.length) {
node = tree;
} else {
this._publish(tree.c[path[index]], path, index + 1, name, msg, pid);
this._publish(tree.c["*"], path, index + 1, name, msg, pid);
node = tree.c["**"];
}
if(typeof node != "undefined") {
var callbacks = node.s;
var max = callbacks.length;
for(var i = 0; i < max; i++) {
if(callbacks[i].cb) {
var sc = callbacks[i].scope;
var cb = callbacks[i].cb;
var fcb = callbacks[i].fcb;
var d = callbacks[i].data;
if(typeof cb == "string"){
// get a function object
cb = sc[cb];
}
if(typeof fcb == "string"){
// get a function object
fcb = sc[fcb];
}
if((!fcb) || (fcb.call(sc, name, msg, d))) {
cb.call(sc, name, msg, d, pid);
}
}
}
}
}
}
h._unsubscribe = function(tree, path, index, sid) {
if(typeof tree != "undefined") {
if(index < path.length) {
var childNode = tree.c[path[index]];
this._unsubscribe(childNode, path, index + 1, sid);
if(childNode.s.length == 0) {
for(var x in childNode.c)
return;
delete tree.c[path[index]];
}
return;
}
else {
var callbacks = tree.s;
var max = callbacks.length;
for(var i = 0; i < max; i++)
if(sid == callbacks[i].sid) {
if(this._pubDepth > 0) {
callbacks[i].cb = null;
this._cleanup.push(callbacks[i]);
}
else
callbacks.splice(i, 1);
return;
}
}
}
}
// The following function is provided for automatic testing purposes.
// It is not expected to be deployed in run-time OpenAjax Hub implementations.
h.reinit = function()
{
for (var lib in OpenAjax.hub.libraries) {
delete OpenAjax.hub.libraries[lib];
}
OpenAjax.hub.registerLibrary("OpenAjax", "http://openajax.org/hub", "1.0", {});
delete OpenAjax._subscriptions;
OpenAjax._subscriptions = {c:{},s:[]};
delete OpenAjax._cleanup;
OpenAjax._cleanup = [];
OpenAjax._subIndex = 0;
OpenAjax._pubDepth = 0;
}
};
// Register the OpenAjax Hub itself as a library.
OpenAjax.hub.registerLibrary("OpenAjax", "http://openajax.org/hub", "1.0", {});
}

View File

@@ -15,7 +15,6 @@ namespace Orchard.MediaPicker {
// should only run on a full view rendering result
if (!(filterContext.Result is ViewResult) || !Orchard.UI.Admin.AdminFilter.IsApplied(filterContext.RequestContext))
return;
_resourceManager.Require("script", "OpenAjax");
_resourceManager.Require("script", "jQuery");
_resourceManager.Include("script", "~/Modules/Orchard.MediaPicker/Scripts/MediaPicker.js", null);
}

View File

@@ -134,8 +134,6 @@
}
function publishInsertEvent(button) {
var prefix = getIdPrefix(button),
editorId = query("editorId"),
source = query("source"),
img = {
src: $(prefix + "src").val(),
alt: $(prefix + "alt").val(),
@@ -146,10 +144,7 @@
height: $(prefix + "height").val()
};
img.html = getImageHtml(img);
window.opener.OpenAjax.hub.publish("orchard.admin.pickimage-picked." + source, {
editorId: editorId,
img: img
});
window.opener.jQuery[query("callback")]({ img: img });
window.close();
}

View File

@@ -1,17 +1,26 @@
(function () {
var eventPrefix = "orchard.admin.pickimage-open.",
pickerAction = "/MediaPicker",
defaultFeatures = "width=800,height=600,status=no,toolbar=no,location=no,menubar=no,resizable=no";
jQuery(function ($) {
$("form").bind("orchard-admin-pickimage-open", function (ev, data) {
data = data || {};
// the popup will be doing full page reloads, so will not be able to retain
// a pointer to the callback. We will generate a temporary callback
// with a known/unique name and pass that in on the querystring so it
// is remembers across reloads. Once executed, it calls the real callback
// and removes itself.
var callbackName = "_pickimage_" + new Date().getTime();
data.callbackName = callbackName;
$[callbackName] = function (returnData) {
delete $[callbackName];
data.callback(returnData);
};
OpenAjax.hub.subscribe(eventPrefix + "*", function (name, data) {
var adminIndex = location.href.toLowerCase().indexOf("/admin/");
if (adminIndex === -1) return;
var url = location.href.substr(0, adminIndex)
+ pickerAction + "?source=" + name.substr(eventPrefix.length)
+ "&uploadpath=" + (data.uploadMediaPath || "")
+ "/MediaPicker?uploadpath=" + (data.uploadMediaPath || "")
+ "&callback=" + callbackName
+ "&editmode=" + (!!(data.img && data.img.src))
+ "&editorId=" + data.editorId + "&" + (new Date() - 0);
var w = window.open(url, "_blank", data.windowFeatures || defaultFeatures);
+ "&" + (new Date() - 0);
var w = window.open(url, "_blank", data.windowFeatures || "width=800,height=600,status=no,toolbar=no,location=no,menubar=no,resizable=no");
if (w.jQuery && w.jQuery.mediaPicker) {
w.jQuery.mediaPicker.init(data);
}
@@ -19,20 +28,4 @@
w.mediaPickerData = data;
}
});
})();
//// Or, with jQuery
//(function ($) {
// $.orchardHub = $.orchardHub || {}; // this part would be built into the admin.js script or something
// $($.orchardHub).bind("orchard-admin-pickimage", function(ev, data) {
// var adminIndex = location.href.toLowerCase().indexOf("/admin/");
// if (adminIndex === -1) return;
// var url = location.href.substr(0, adminIndex)
// + "/Orchard.MediaPicker/MediaPicker/Index?source=" + data.source
// + "&editorId=" + data.editorId + "&" + (new Date() - 0);
// var w = window.open(url, "Orchard.MediaPicker", data.windowFeatures || "width=600,height=300,status=no,toolbar=no,location=no,menubar=no");
// // in case it was already open, bring to the fore
// w.focus();
// });
//})(jQuery);
});

View File

@@ -8,10 +8,9 @@
// querystring values need to persist after a new GET when clicking on the media browser's
// folders for navigation.
@Html.ActionLink(folderName, "Index", null, null, null, "tab=1", new {
callback = Request["callback"],
uploadpath = Request["uploadpath"],
editmode = Request["editmode"],
source = Request["source"],
editorId = Request["editorId"],
name = folderName,
mediaPath = mediaPath }, null);
}

View File

@@ -1,3 +1,2 @@
(function(){OpenAjax.hub.subscribe("orchard.admin.pickimage-picked.tinymce",function(b,d){var c=tinyMCE.get(d.editorId);c.focus();c.selection.setContent(d.img.html)});tinymce.create("tinymce.plugins.Orchard.MediaPicker",{init:function(b,d){b.addCommand("mceMediaPicker",function(){b.focus();var c,a=b.selection.getContent();if(a){a=a.replace(/\<IMG/gi,"<editimg");a=$(a).filter("editimg");if(a.length)c={src:a.attr("src"),"class":a.attr("class"),style:a.css("cssText"),alt:a.attr("alt"),width:a.attr("width"),
height:a.attr("height"),align:a.attr("align")}}OpenAjax.hub.publish("orchard.admin.pickimage-open.tinymce",{editorId:b.id,img:c,uploadMediaPath:b.getParam("mediapicker_uploadpath")})});b.addButton("mediapicker",{title:b.getParam("mediapicker_title"),cmd:"mceMediaPicker",image:d+"/img/picture_add.png"})},createControl:function(){return null},getInfo:function(){return{longname:"Orchard AddMedia Plugin",author:"Dave Reed",authorurl:"http://orchardproject.net",infourl:"http://orchardproject.net",version:"1.1"}}});
tinymce.PluginManager.add("mediapicker",tinymce.plugins.Orchard.MediaPicker)})();
(function(){tinymce.create("tinymce.plugins.Orchard.MediaPicker",{init:function(b,d){b.addCommand("mceMediaPicker",function(){b.focus();var c,a=b.selection.getContent();if(a){a=a.replace(/\<IMG/gi,"<editimg");a=$(a).filter("editimg");if(a.length)c={src:a.attr("src"),"class":a.attr("class"),style:a.css("cssText"),alt:a.attr("alt"),width:a.attr("width"),height:a.attr("height"),align:a.attr("align")}}jQuery("#"+b.id).trigger("orchard-admin-pickimage-open",{img:c,uploadMediaPath:b.getParam("mediapicker_uploadpath"),
callback:function(e){b.focus();b.selection.setContent(e.img.html)}})});b.addButton("mediapicker",{title:b.getParam("mediapicker_title"),cmd:"mceMediaPicker",image:d+"/img/picture_add.png"})},createControl:function(){return null},getInfo:function(){return{longname:"Orchard MediaPicker Plugin",author:"Dave Reed",authorurl:"http://orchardproject.net",infourl:"http://orchardproject.net",version:"1.1"}}});tinymce.PluginManager.add("mediapicker",tinymce.plugins.Orchard.MediaPicker)})();

View File

@@ -4,14 +4,6 @@
// NOTE: IF YOU EDIT THIS FILE
// You must also update editor_plugin.js with a minified version.
////////////////////////////////////////////////////////////////////////
// when the picker selects an image, notice the event and update the editor.
OpenAjax.hub.subscribe("orchard.admin.pickimage-picked.tinymce", function (name, data) {
var ed = tinyMCE.get(data.editorId);
ed.focus();
ed.selection.setContent(data.img.html);
});
tinymce.create('tinymce.plugins.Orchard.MediaPicker', {
/**
* Initializes the plugin, this will be executed after the plugin has been created.
@@ -45,10 +37,13 @@
};
}
}
OpenAjax.hub.publish("orchard.admin.pickimage-open.tinymce", {
editorId: ed.id,
jQuery("#" + ed.id).trigger("orchard-admin-pickimage-open", {
img: editImage,
uploadMediaPath: ed.getParam("mediapicker_uploadpath")
uploadMediaPath: ed.getParam("mediapicker_uploadpath"),
callback: function (data) {
ed.focus();
ed.selection.setContent(data.img.html);
}
});
});
@@ -82,7 +77,7 @@
*/
getInfo: function () {
return {
longname: 'Orchard AddMedia Plugin',
longname: 'Orchard MediaPicker Plugin',
author: 'Dave Reed',
authorurl: 'http://orchardproject.net',
infourl: 'http://orchardproject.net',

View File

@@ -10,7 +10,6 @@
Style.Include("ie.css").UseCondition("lte IE 8").SetAttribute("media", "screen, projection");
Style.Include("ie6.css").UseCondition("lte IE 6").SetAttribute("media", "screen, projection");
Script.Require("jQuery");
Script.Require("OpenAjax");
Script.Require("ShapesBase");
Script.Include("admin.js");