kublog 0.0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +177 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +102 -0
- data/Rakefile +39 -0
- data/app/assets/images/kublog/.gitkeep +0 -0
- data/app/assets/images/kublog/missing_image.png +0 -0
- data/app/assets/javascripts/kublog/application.js +13 -0
- data/app/assets/javascripts/kublog/categories.js.coffee +48 -0
- data/app/assets/javascripts/kublog/comments.js.coffee +30 -0
- data/app/assets/javascripts/kublog/email.js.coffee +32 -0
- data/app/assets/javascripts/kublog/images.js.coffee +77 -0
- data/app/assets/javascripts/kublog/posts.js.coffee +44 -0
- data/app/assets/javascripts/kublog/shared.js.coffee.erb +19 -0
- data/app/assets/javascripts/kublog/wysiwyg.controls.js.coffee +68 -0
- data/app/assets/plugins/kublog/ajaxyupload/images/ajax-loader.gif +0 -0
- data/app/assets/plugins/kublog/ajaxyupload/javascripts/jquery.ajaxyupload.js +126 -0
- data/app/assets/plugins/kublog/fancybox/images/blank.gif +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_close.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_loading.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_nav_left.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_nav_right.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_shadow_e.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_shadow_n.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_shadow_ne.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_shadow_nw.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_shadow_s.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_shadow_se.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_shadow_sw.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_shadow_w.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_title_left.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_title_main.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_title_over.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancy_title_right.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancybox-x.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancybox-y.png +0 -0
- data/app/assets/plugins/kublog/fancybox/images/fancybox.png +0 -0
- data/app/assets/plugins/kublog/fancybox/javascripts/fancybox-1.3.4.js +46 -0
- data/app/assets/plugins/kublog/fancybox/stylesheets/fancybox-1.3.4.css +359 -0
- data/app/assets/plugins/kublog/livequery/javascripts/jquery.livequery.js +250 -0
- data/app/assets/plugins/kublog/wysiwyg/images/ajax-loader.gif +0 -0
- data/app/assets/plugins/kublog/wysiwyg/images/jquery.wysiwyg.bg.png +0 -0
- data/app/assets/plugins/kublog/wysiwyg/images/jquery.wysiwyg.gif +0 -0
- data/app/assets/plugins/kublog/wysiwyg/images/jquery.wysiwyg.jpg +0 -0
- data/app/assets/plugins/kublog/wysiwyg/images/jquery.wysiwyg.no-alpha.gif +0 -0
- data/app/assets/plugins/kublog/wysiwyg/javascripts/jquery.wysiwyg.js +2377 -0
- data/app/assets/plugins/kublog/wysiwyg/javascripts/wysiwyg.image.js +284 -0
- data/app/assets/plugins/kublog/wysiwyg/javascripts/wysiwyg.link.js +249 -0
- data/app/assets/plugins/kublog/wysiwyg/stylesheets/jquery.wysiwyg.css +94 -0
- data/app/assets/stylesheets/kublog/application.css +9 -0
- data/app/assets/stylesheets/kublog/categories.css +4 -0
- data/app/assets/stylesheets/kublog/comments.css +4 -0
- data/app/assets/stylesheets/kublog/email.css +7 -0
- data/app/assets/stylesheets/kublog/images.css +41 -0
- data/app/assets/stylesheets/kublog/posts.css +39 -0
- data/app/controllers/kublog/application_controller.rb +12 -0
- data/app/controllers/kublog/categories_controller.rb +47 -0
- data/app/controllers/kublog/comments_controller.rb +37 -0
- data/app/controllers/kublog/images_controller.rb +44 -0
- data/app/controllers/kublog/posts_controller.rb +66 -0
- data/app/helpers/kublog/application_helper.rb +4 -0
- data/app/helpers/kublog/posts_helper.rb +38 -0
- data/app/mailers/kublog/post_mailer.rb +11 -0
- data/app/models/kublog/category.rb +26 -0
- data/app/models/kublog/comment.rb +46 -0
- data/app/models/kublog/image.rb +23 -0
- data/app/models/kublog/post.rb +51 -0
- data/app/presenters/kublog/post_presenter.rb +23 -0
- data/app/presenters/kublog/posts_presenter.rb +29 -0
- data/app/uploaders/kublog/file_uploader.rb +56 -0
- data/app/views/kublog/post_mailer/new_post.html.erb +1 -0
- data/app/views/kublog/post_mailer/new_post.liquid.html.erb +7 -0
- data/app/views/kublog/posts/_email_form.html.erb +13 -0
- data/app/views/kublog/posts/_form.html.erb +71 -0
- data/app/views/kublog/posts/_image_form.html.erb +26 -0
- data/app/views/kublog/posts/edit.html.erb +3 -0
- data/app/views/kublog/posts/index.atom.builder +15 -0
- data/app/views/kublog/posts/index.html.erb +36 -0
- data/app/views/kublog/posts/new.html.erb +3 -0
- data/app/views/kublog/posts/show.html.erb +46 -0
- data/app/views/layouts/kublog/application.html.erb +14 -0
- data/config/locales/kublog/en.yml +54 -0
- data/config/routes.rb +13 -0
- data/db/migrate/20110816211552_create_kublog_posts.rb +27 -0
- data/db/migrate/20110817215828_create_kublog_images.rb +11 -0
- data/db/migrate/20110818181434_create_kublog_categories.rb +11 -0
- data/db/migrate/20110822194341_create_kublog_comments.rb +14 -0
- data/kublog.gemspec +39 -0
- data/lib/kublog.rb +92 -0
- data/lib/kublog/author.rb +13 -0
- data/lib/kublog/engine.rb +5 -0
- data/lib/kublog/notifiable.rb +26 -0
- data/lib/kublog/notification/email.rb +86 -0
- data/lib/kublog/notification/email_job.rb +14 -0
- data/lib/kublog/notification/fb_post.rb +43 -0
- data/lib/kublog/notification/fb_post_job.rb +16 -0
- data/lib/kublog/notification/tweet.rb +68 -0
- data/lib/kublog/notification/tweet_job.rb +16 -0
- data/lib/kublog/user_integration/common.rb +31 -0
- data/lib/kublog/user_integration/devise.rb +23 -0
- data/lib/kublog/version.rb +3 -0
- data/lib/kublog/xhr_upload/file_helper.rb +36 -0
- data/lib/tasks/kublog_tasks.rake +4 -0
- data/script/rails +6 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +9 -0
- data/test/dummy/app/assets/javascripts/sessions.js +2 -0
- data/test/dummy/app/assets/javascripts/users.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +157 -0
- data/test/dummy/app/assets/stylesheets/sessions.css +4 -0
- data/test/dummy/app/assets/stylesheets/users.css +4 -0
- data/test/dummy/app/controllers/application_controller.rb +19 -0
- data/test/dummy/app/controllers/sessions_controller.rb +22 -0
- data/test/dummy/app/controllers/users_controller.rb +17 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/error_messages_helper.rb +23 -0
- data/test/dummy/app/helpers/layout_helper.rb +22 -0
- data/test/dummy/app/helpers/sessions_helper.rb +2 -0
- data/test/dummy/app/helpers/users_helper.rb +2 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/models/ability.rb +2 -0
- data/test/dummy/app/models/user.rb +25 -0
- data/test/dummy/app/views/layouts/_account.html.erb +8 -0
- data/test/dummy/app/views/layouts/application.html.erb +29 -0
- data/test/dummy/app/views/layouts/kublog/application.html.erb +31 -0
- data/test/dummy/app/views/sessions/new.html.erb +15 -0
- data/test/dummy/app/views/users/new.html.erb +28 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +42 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +38 -0
- data/test/dummy/config/environments/production.rb +51 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/test/dummy/config/locales/en.yml +54 -0
- data/test/dummy/config/routes.rb +13 -0
- data/test/dummy/db/migrate/20110816225222_create_users.rb +11 -0
- data/test/dummy/db/migrate/20110819135547_create_delayed_jobs.rb +21 -0
- data/test/dummy/db/schema.rb +96 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/delayed_job +5 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/users.yml +9 -0
- data/test/dummy/test/functional/sessions_controller_test.rb +7 -0
- data/test/dummy/test/functional/users_controller_test.rb +7 -0
- data/test/dummy/test/unit/helpers/sessions_helper_test.rb +4 -0
- data/test/dummy/test/unit/helpers/users_helper_test.rb +4 -0
- data/test/dummy/test/unit/user_test.rb +7 -0
- data/test/factories.rb +9 -0
- data/test/fixtures/kublog/categories.yml +7 -0
- data/test/fixtures/kublog/comments.yml +7 -0
- data/test/fixtures/kublog/images.yml +9 -0
- data/test/fixtures/kublog/posts.yml +9 -0
- data/test/functional/kublog/categories_controller_test.rb +9 -0
- data/test/functional/kublog/comments_controller_test.rb +9 -0
- data/test/functional/kublog/images_controller_test.rb +9 -0
- data/test/functional/kublog/post_mailer_test.rb +9 -0
- data/test/functional/kublog/posts_controller_test.rb +9 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/kublog_test.rb +7 -0
- data/test/test_helper.rb +12 -0
- data/test/unit/helpers/kublog/categories_helper_test.rb +6 -0
- data/test/unit/helpers/kublog/comments_helper_test.rb +6 -0
- data/test/unit/helpers/kublog/images_helper_test.rb +6 -0
- data/test/unit/helpers/kublog/posts_helper_test.rb +6 -0
- data/test/unit/kublog/category_test.rb +9 -0
- data/test/unit/kublog/comment_test.rb +9 -0
- data/test/unit/kublog/image_test.rb +9 -0
- data/test/unit/kublog/post_test.rb +19 -0
- metadata +439 -0
@@ -0,0 +1,284 @@
|
|
1
|
+
/**
|
2
|
+
* Controls: Image plugin
|
3
|
+
*
|
4
|
+
* Depends on jWYSIWYG
|
5
|
+
*/
|
6
|
+
(function ($) {
|
7
|
+
"use strict";
|
8
|
+
|
9
|
+
if (undefined === $.wysiwyg) {
|
10
|
+
throw "wysiwyg.image.js depends on $.wysiwyg";
|
11
|
+
}
|
12
|
+
|
13
|
+
if (!$.wysiwyg.controls) {
|
14
|
+
$.wysiwyg.controls = {};
|
15
|
+
}
|
16
|
+
|
17
|
+
/*
|
18
|
+
* Wysiwyg namespace: public properties and methods
|
19
|
+
*/
|
20
|
+
$.wysiwyg.controls.image = {
|
21
|
+
groupIndex: 6,
|
22
|
+
visible: true,
|
23
|
+
exec: function () {
|
24
|
+
$.wysiwyg.controls.image.init(this);
|
25
|
+
},
|
26
|
+
tags: ["img"],
|
27
|
+
tooltip: "Insert image",
|
28
|
+
init: function (Wysiwyg) {
|
29
|
+
var self = this, elements, adialog, dialog, formImageHtml, regexp, dialogReplacements, key, translation,
|
30
|
+
img = {
|
31
|
+
alt: "",
|
32
|
+
self: Wysiwyg.dom ? Wysiwyg.dom.getElement("img") : null, // link to element node
|
33
|
+
src: "http://",
|
34
|
+
title: ""
|
35
|
+
};
|
36
|
+
|
37
|
+
dialogReplacements = {
|
38
|
+
legend : "Insert Image",
|
39
|
+
preview : "Preview",
|
40
|
+
url : "URL",
|
41
|
+
title : "Title",
|
42
|
+
description : "Description",
|
43
|
+
width : "Width",
|
44
|
+
height : "Height",
|
45
|
+
original : "Original W x H",
|
46
|
+
"float" : "Float",
|
47
|
+
floatNone : "None",
|
48
|
+
floatLeft : "Left",
|
49
|
+
floatRight : "Right",
|
50
|
+
submit : "Insert Image",
|
51
|
+
reset : "Cancel",
|
52
|
+
fileManagerIcon : "Select file from server"
|
53
|
+
};
|
54
|
+
|
55
|
+
formImageHtml = '<form class="wysiwyg" id="wysiwyg-addImage"><fieldset>' +
|
56
|
+
'<div class="form-row"><span class="form-row-key">{preview}:</span><div class="form-row-value"><img src="" alt="{preview}" style="margin: 2px; padding:5px; max-width: 100%; overflow:hidden; max-height: 100px; border: 1px solid rgb(192, 192, 192);"/></div></div>' +
|
57
|
+
'<div class="form-row"><label for="name">{url}:</label><div class="form-row-value"><input type="text" name="src" value=""/>';
|
58
|
+
|
59
|
+
if ($.wysiwyg.fileManager && $.wysiwyg.fileManager.ready) {
|
60
|
+
// Add the File Manager icon:
|
61
|
+
formImageHtml += '<div class="wysiwyg-fileManager" title="{fileManagerIcon}"/>';
|
62
|
+
}
|
63
|
+
|
64
|
+
formImageHtml += '</div></div>' +
|
65
|
+
'<div class="form-row"><label for="name">{title}:</label><div class="form-row-value"><input type="text" name="imgtitle" value=""/></div></div>' +
|
66
|
+
'<div class="form-row"><label for="name">{description}:</label><div class="form-row-value"><input type="text" name="description" value=""/></div></div>' +
|
67
|
+
'<div class="form-row"><label for="name">{width} x {height}:</label><div class="form-row-value"><input type="text" name="width" value="" class="width-small"/> x <input type="text" name="height" value="" class="width-small"/></div></div>' +
|
68
|
+
'<div class="form-row"><label for="name">{original}:</label><div class="form-row-value"><input type="text" name="naturalWidth" value="" class="width-small" disabled="disabled"/> x ' +
|
69
|
+
'<input type="text" name="naturalHeight" value="" class="width-small" disabled="disabled"/></div></div>' +
|
70
|
+
'<div class="form-row"><label for="name">{float}:</label><div class="form-row-value"><select name="float">' +
|
71
|
+
'<option value="">{floatNone}</option>' +
|
72
|
+
'<option value="left">{floatLeft}</option>' +
|
73
|
+
'<option value="right">{floatRight}</option></select></div></div>' +
|
74
|
+
'<div class="form-row form-row-last"><label for="name"></label><div class="form-row-value"><input type="submit" class="button" value="{submit}"/> ' +
|
75
|
+
'<input type="reset" value="{reset}"/></div></div></fieldset></form>';
|
76
|
+
|
77
|
+
for (key in dialogReplacements) {
|
78
|
+
if ($.wysiwyg.i18n) {
|
79
|
+
translation = $.wysiwyg.i18n.t(dialogReplacements[key], "dialogs.image");
|
80
|
+
|
81
|
+
if (translation === dialogReplacements[key]) { // if not translated search in dialogs
|
82
|
+
translation = $.wysiwyg.i18n.t(dialogReplacements[key], "dialogs");
|
83
|
+
}
|
84
|
+
|
85
|
+
dialogReplacements[key] = translation;
|
86
|
+
}
|
87
|
+
|
88
|
+
regexp = new RegExp("{" + key + "}", "g");
|
89
|
+
formImageHtml = formImageHtml.replace(regexp, dialogReplacements[key]);
|
90
|
+
}
|
91
|
+
|
92
|
+
if (img.self) {
|
93
|
+
img.src = img.self.src ? img.self.src : "";
|
94
|
+
img.alt = img.self.alt ? img.self.alt : "";
|
95
|
+
img.title = img.self.title ? img.self.title : "";
|
96
|
+
img.width = img.self.width ? img.self.width : "";
|
97
|
+
img.height = img.self.height ? img.self.height : "";
|
98
|
+
img.styleFloat = $(img.self).css("float");
|
99
|
+
}
|
100
|
+
|
101
|
+
adialog = new $.wysiwyg.dialog(Wysiwyg, {
|
102
|
+
"title" : dialogReplacements.legend,
|
103
|
+
"content" : formImageHtml
|
104
|
+
});
|
105
|
+
|
106
|
+
$(adialog).bind("afterOpen", function (e, dialog) {
|
107
|
+
dialog.find("form#wysiwyg-addImage").submit(function (e) {
|
108
|
+
e.preventDefault();
|
109
|
+
self.processInsert(dialog.container, Wysiwyg, img);
|
110
|
+
|
111
|
+
adialog.close();
|
112
|
+
return false;
|
113
|
+
});
|
114
|
+
|
115
|
+
// File Manager (select file):
|
116
|
+
if ($.wysiwyg.fileManager) {
|
117
|
+
$("div.wysiwyg-fileManager").bind("click", function () {
|
118
|
+
$.wysiwyg.fileManager.init(function (selected) {
|
119
|
+
dialog.find("input[name=src]").val(selected);
|
120
|
+
dialog.find("input[name=src]").trigger("change");
|
121
|
+
});
|
122
|
+
});
|
123
|
+
}
|
124
|
+
|
125
|
+
$("input:reset", dialog).click(function (e) {
|
126
|
+
adialog.close();
|
127
|
+
|
128
|
+
return false;
|
129
|
+
});
|
130
|
+
|
131
|
+
$("fieldset", dialog).click(function (e) {
|
132
|
+
e.stopPropagation();
|
133
|
+
});
|
134
|
+
|
135
|
+
self.makeForm(dialog, img);
|
136
|
+
});
|
137
|
+
|
138
|
+
adialog.open();
|
139
|
+
|
140
|
+
$(Wysiwyg.editorDoc).trigger("editorRefresh.wysiwyg");
|
141
|
+
},
|
142
|
+
|
143
|
+
processInsert: function (context, Wysiwyg, img) {
|
144
|
+
var image,
|
145
|
+
url = $('input[name="src"]', context).val(),
|
146
|
+
title = $('input[name="imgtitle"]', context).val(),
|
147
|
+
description = $('input[name="description"]', context).val(),
|
148
|
+
width = $('input[name="width"]', context).val(),
|
149
|
+
height = $('input[name="height"]', context).val(),
|
150
|
+
styleFloat = $('select[name="float"]', context).val(),
|
151
|
+
styles = [],
|
152
|
+
style = "",
|
153
|
+
found,
|
154
|
+
baseUrl;
|
155
|
+
|
156
|
+
if (Wysiwyg.options.controlImage && Wysiwyg.options.controlImage.forceRelativeUrls) {
|
157
|
+
baseUrl = window.location.protocol + "//" + window.location.hostname;
|
158
|
+
if (0 === url.indexOf(baseUrl)) {
|
159
|
+
url = url.substr(baseUrl.length);
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
if (img.self) {
|
164
|
+
// to preserve all img attributes
|
165
|
+
$(img.self).attr("src", url)
|
166
|
+
.attr("title", title)
|
167
|
+
.attr("alt", description)
|
168
|
+
.css("float", styleFloat);
|
169
|
+
|
170
|
+
if (width.toString().match(/^[0-9]+(px|%)?$/)) {
|
171
|
+
$(img.self).css("width", width);
|
172
|
+
} else {
|
173
|
+
$(img.self).css("width", "");
|
174
|
+
}
|
175
|
+
|
176
|
+
if (height.toString().match(/^[0-9]+(px|%)?$/)) {
|
177
|
+
$(img.self).css("height", height);
|
178
|
+
} else {
|
179
|
+
$(img.self).css("height", "");
|
180
|
+
}
|
181
|
+
|
182
|
+
Wysiwyg.saveContent();
|
183
|
+
} else {
|
184
|
+
found = width.toString().match(/^[0-9]+(px|%)?$/);
|
185
|
+
if (found) {
|
186
|
+
if (found[1]) {
|
187
|
+
styles.push("width: " + width + ";");
|
188
|
+
} else {
|
189
|
+
styles.push("width: " + width + "px;");
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
found = height.toString().match(/^[0-9]+(px|%)?$/);
|
194
|
+
if (found) {
|
195
|
+
if (found[1]) {
|
196
|
+
styles.push("height: " + height + ";");
|
197
|
+
} else {
|
198
|
+
styles.push("height: " + height + "px;");
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
if (styleFloat.length > 0) {
|
203
|
+
styles.push("float: " + styleFloat + ";");
|
204
|
+
}
|
205
|
+
|
206
|
+
if (styles.length > 0) {
|
207
|
+
style = ' style="' + styles.join(" ") + '"';
|
208
|
+
}
|
209
|
+
|
210
|
+
image = "<img src='" + url + "' title='" + title + "' alt='" + description + "'" + style + "/>";
|
211
|
+
Wysiwyg.insertHtml(image);
|
212
|
+
}
|
213
|
+
},
|
214
|
+
|
215
|
+
makeForm: function (form, img) {
|
216
|
+
form.find("input[name=src]").val(img.src);
|
217
|
+
form.find("input[name=imgtitle]").val(img.title);
|
218
|
+
form.find("input[name=description]").val(img.alt);
|
219
|
+
form.find('input[name="width"]').val(img.width);
|
220
|
+
form.find('input[name="height"]').val(img.height);
|
221
|
+
form.find('select[name="float"]').val(img.styleFloat);
|
222
|
+
form.find('img').attr("src", img.src);
|
223
|
+
|
224
|
+
form.find('img').bind("load", function () {
|
225
|
+
if (form.find('img').get(0).naturalWidth) {
|
226
|
+
form.find('input[name="naturalWidth"]').val(form.find('img').get(0).naturalWidth);
|
227
|
+
form.find('input[name="naturalHeight"]').val(form.find('img').get(0).naturalHeight);
|
228
|
+
} else if (form.find('img').attr("naturalWidth")) {
|
229
|
+
form.find('input[name="naturalWidth"]').val(form.find('img').attr("naturalWidth"));
|
230
|
+
form.find('input[name="naturalHeight"]').val(form.find('img').attr("naturalHeight"));
|
231
|
+
}
|
232
|
+
});
|
233
|
+
|
234
|
+
form.find("input[name=src]").bind("change", function () {
|
235
|
+
form.find('img').attr("src", this.value);
|
236
|
+
});
|
237
|
+
|
238
|
+
return form;
|
239
|
+
}
|
240
|
+
};
|
241
|
+
|
242
|
+
$.wysiwyg.insertImage = function (object, url, attributes) {
|
243
|
+
return object.each(function () {
|
244
|
+
var Wysiwyg = $(this).data("wysiwyg"),
|
245
|
+
image,
|
246
|
+
attribute;
|
247
|
+
|
248
|
+
if (!Wysiwyg) {
|
249
|
+
return this;
|
250
|
+
}
|
251
|
+
|
252
|
+
if (!url || url.length === 0) {
|
253
|
+
return this;
|
254
|
+
}
|
255
|
+
|
256
|
+
if ($.browser.msie) {
|
257
|
+
Wysiwyg.ui.focus();
|
258
|
+
}
|
259
|
+
|
260
|
+
if (attributes) {
|
261
|
+
Wysiwyg.editorDoc.execCommand("insertImage", false, "#jwysiwyg#");
|
262
|
+
image = Wysiwyg.getElementByAttributeValue("img", "src", "#jwysiwyg#");
|
263
|
+
|
264
|
+
if (image) {
|
265
|
+
image.src = url;
|
266
|
+
|
267
|
+
for (attribute in attributes) {
|
268
|
+
if (attributes.hasOwnProperty(attribute)) {
|
269
|
+
image.setAttribute(attribute, attributes[attribute]);
|
270
|
+
}
|
271
|
+
}
|
272
|
+
}
|
273
|
+
} else {
|
274
|
+
Wysiwyg.editorDoc.execCommand("insertImage", false, url);
|
275
|
+
}
|
276
|
+
|
277
|
+
Wysiwyg.saveContent();
|
278
|
+
|
279
|
+
$(Wysiwyg.editorDoc).trigger("editorRefresh.wysiwyg");
|
280
|
+
|
281
|
+
return this;
|
282
|
+
});
|
283
|
+
};
|
284
|
+
})(jQuery);
|
@@ -0,0 +1,249 @@
|
|
1
|
+
/**
|
2
|
+
* Controls: Link plugin
|
3
|
+
*
|
4
|
+
* Depends on jWYSIWYG
|
5
|
+
*
|
6
|
+
* By: Esteban Beltran (academo) <sergies@gmail.com>
|
7
|
+
*/
|
8
|
+
(function ($) {
|
9
|
+
"use strict";
|
10
|
+
|
11
|
+
if (undefined === $.wysiwyg) {
|
12
|
+
throw "wysiwyg.link.js depends on $.wysiwyg";
|
13
|
+
}
|
14
|
+
|
15
|
+
if (!$.wysiwyg.controls) {
|
16
|
+
$.wysiwyg.controls = {};
|
17
|
+
}
|
18
|
+
|
19
|
+
/*
|
20
|
+
* Wysiwyg namespace: public properties and methods
|
21
|
+
*/
|
22
|
+
$.wysiwyg.controls.link = {
|
23
|
+
init: function (Wysiwyg) {
|
24
|
+
var self = this, elements, dialog, url, a, selection,
|
25
|
+
formLinkHtml, dialogReplacements, key, translation, regexp,
|
26
|
+
baseUrl, img;
|
27
|
+
|
28
|
+
dialogReplacements = {
|
29
|
+
legend: "Insert Link",
|
30
|
+
url : "Link URL",
|
31
|
+
title : "Link Title",
|
32
|
+
target: "Link Target",
|
33
|
+
submit: "Insert Link",
|
34
|
+
reset: "Cancel"
|
35
|
+
};
|
36
|
+
|
37
|
+
formLinkHtml = '<form class="wysiwyg"><fieldset><legend>{legend}</legend>' +
|
38
|
+
'<label>{url}: <input type="text" name="linkhref" value=""/></label>' +
|
39
|
+
'<label>{title}: <input type="text" name="linktitle" value=""/></label>' +
|
40
|
+
'<label>{target}: <input type="text" name="linktarget" value=""/></label>' +
|
41
|
+
'<input type="submit" class="button" value="{submit}"/> ' +
|
42
|
+
'<input type="reset" value="{reset}"/></fieldset></form>';
|
43
|
+
|
44
|
+
for (key in dialogReplacements) {
|
45
|
+
if ($.wysiwyg.i18n) {
|
46
|
+
translation = $.wysiwyg.i18n.t(dialogReplacements[key], "dialogs.link");
|
47
|
+
|
48
|
+
if (translation === dialogReplacements[key]) { // if not translated search in dialogs
|
49
|
+
translation = $.wysiwyg.i18n.t(dialogReplacements[key], "dialogs");
|
50
|
+
}
|
51
|
+
|
52
|
+
dialogReplacements[key] = translation;
|
53
|
+
}
|
54
|
+
|
55
|
+
regexp = new RegExp("{" + key + "}", "g");
|
56
|
+
formLinkHtml = formLinkHtml.replace(regexp, dialogReplacements[key]);
|
57
|
+
}
|
58
|
+
|
59
|
+
a = {
|
60
|
+
self: Wysiwyg.dom.getElement("a"), // link to element node
|
61
|
+
href: "http://",
|
62
|
+
title: "",
|
63
|
+
target: ""
|
64
|
+
};
|
65
|
+
|
66
|
+
if (a.self) {
|
67
|
+
a.href = a.self.href ? a.self.href : a.href;
|
68
|
+
a.title = a.self.title ? a.self.title : "";
|
69
|
+
a.target = a.self.target ? a.self.target : "";
|
70
|
+
}
|
71
|
+
|
72
|
+
if ($.fn.dialog) {
|
73
|
+
elements = $(formLinkHtml);
|
74
|
+
elements.find("input[name=linkhref]").val(a.href);
|
75
|
+
elements.find("input[name=linktitle]").val(a.title);
|
76
|
+
elements.find("input[name=linktarget]").val(a.target);
|
77
|
+
|
78
|
+
if ($.browser.msie) {
|
79
|
+
try {
|
80
|
+
dialog = elements.appendTo(Wysiwyg.editorDoc.body);
|
81
|
+
} catch (err) {
|
82
|
+
dialog = elements.appendTo("body");
|
83
|
+
}
|
84
|
+
} else {
|
85
|
+
dialog = elements.appendTo("body");
|
86
|
+
}
|
87
|
+
|
88
|
+
dialog.dialog({
|
89
|
+
modal: true,
|
90
|
+
open: function (ev, ui) {
|
91
|
+
$("input:submit", dialog).click(function (e) {
|
92
|
+
e.preventDefault();
|
93
|
+
|
94
|
+
var url = $('input[name="linkhref"]', dialog).val(),
|
95
|
+
title = $('input[name="linktitle"]', dialog).val(),
|
96
|
+
target = $('input[name="linktarget"]', dialog).val(),
|
97
|
+
baseUrl,
|
98
|
+
img;
|
99
|
+
|
100
|
+
if (Wysiwyg.options.controlLink.forceRelativeUrls) {
|
101
|
+
baseUrl = window.location.protocol + "//" + window.location.hostname;
|
102
|
+
if (0 === url.indexOf(baseUrl)) {
|
103
|
+
url = url.substr(baseUrl.length);
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
if (a.self) {
|
108
|
+
if ("string" === typeof (url)) {
|
109
|
+
if (url.length > 0) {
|
110
|
+
// to preserve all link attributes
|
111
|
+
$(a.self).attr("href", url).attr("title", title).attr("target", target);
|
112
|
+
} else {
|
113
|
+
$(a.self).replaceWith(a.self.innerHTML);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
} else {
|
117
|
+
if ($.browser.msie) {
|
118
|
+
Wysiwyg.ui.returnRange();
|
119
|
+
}
|
120
|
+
|
121
|
+
//Do new link element
|
122
|
+
selection = Wysiwyg.getRangeText();
|
123
|
+
img = Wysiwyg.dom.getElement("img");
|
124
|
+
|
125
|
+
if ((selection && selection.length > 0) || img) {
|
126
|
+
if ($.browser.msie) {
|
127
|
+
Wysiwyg.ui.focus();
|
128
|
+
}
|
129
|
+
|
130
|
+
if ("string" === typeof (url)) {
|
131
|
+
if (url.length > 0) {
|
132
|
+
Wysiwyg.editorDoc.execCommand("createLink", false, url);
|
133
|
+
} else {
|
134
|
+
Wysiwyg.editorDoc.execCommand("unlink", false, null);
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
a.self = Wysiwyg.dom.getElement("a");
|
139
|
+
|
140
|
+
$(a.self).attr("href", url).attr("title", title);
|
141
|
+
|
142
|
+
/**
|
143
|
+
* @url https://github.com/akzhan/jwysiwyg/issues/16
|
144
|
+
*/
|
145
|
+
$(a.self).attr("target", target);
|
146
|
+
} else if (Wysiwyg.options.messages.nonSelection) {
|
147
|
+
window.alert(Wysiwyg.options.messages.nonSelection);
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
Wysiwyg.saveContent();
|
152
|
+
|
153
|
+
$(dialog).dialog("close");
|
154
|
+
});
|
155
|
+
$("input:reset", dialog).click(function (e) {
|
156
|
+
e.preventDefault();
|
157
|
+
$(dialog).dialog("close");
|
158
|
+
});
|
159
|
+
},
|
160
|
+
close: function (ev, ui) {
|
161
|
+
dialog.dialog("destroy");
|
162
|
+
dialog.remove();
|
163
|
+
}
|
164
|
+
});
|
165
|
+
} else {
|
166
|
+
if (a.self) {
|
167
|
+
url = window.prompt("URL", a.href);
|
168
|
+
|
169
|
+
if (Wysiwyg.options.controlLink.forceRelativeUrls) {
|
170
|
+
baseUrl = window.location.protocol + "//" + window.location.hostname;
|
171
|
+
if (0 === url.indexOf(baseUrl)) {
|
172
|
+
url = url.substr(baseUrl.length);
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
if ("string" === typeof (url)) {
|
177
|
+
if (url.length > 0) {
|
178
|
+
$(a.self).attr("href", url);
|
179
|
+
} else {
|
180
|
+
$(a.self).replaceWith(a.self.innerHTML);
|
181
|
+
}
|
182
|
+
}
|
183
|
+
} else {
|
184
|
+
//Do new link element
|
185
|
+
selection = Wysiwyg.getRangeText();
|
186
|
+
img = Wysiwyg.dom.getElement("img");
|
187
|
+
|
188
|
+
if ((selection && selection.length > 0) || img) {
|
189
|
+
if ($.browser.msie) {
|
190
|
+
Wysiwyg.ui.focus();
|
191
|
+
Wysiwyg.editorDoc.execCommand("createLink", true, null);
|
192
|
+
} else {
|
193
|
+
url = window.prompt(dialogReplacements.url, a.href);
|
194
|
+
|
195
|
+
if (Wysiwyg.options.controlLink.forceRelativeUrls) {
|
196
|
+
baseUrl = window.location.protocol + "//" + window.location.hostname;
|
197
|
+
if (0 === url.indexOf(baseUrl)) {
|
198
|
+
url = url.substr(baseUrl.length);
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
if ("string" === typeof (url)) {
|
203
|
+
if (url.length > 0) {
|
204
|
+
Wysiwyg.editorDoc.execCommand("createLink", false, url);
|
205
|
+
} else {
|
206
|
+
Wysiwyg.editorDoc.execCommand("unlink", false, null);
|
207
|
+
}
|
208
|
+
}
|
209
|
+
}
|
210
|
+
} else if (Wysiwyg.options.messages.nonSelection) {
|
211
|
+
window.alert(Wysiwyg.options.messages.nonSelection);
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
Wysiwyg.saveContent();
|
216
|
+
}
|
217
|
+
|
218
|
+
$(Wysiwyg.editorDoc).trigger("editorRefresh.wysiwyg");
|
219
|
+
}
|
220
|
+
};
|
221
|
+
|
222
|
+
$.wysiwyg.createLink = function (object, url) {
|
223
|
+
return object.each(function () {
|
224
|
+
var oWysiwyg = $(this).data("wysiwyg"),
|
225
|
+
selection;
|
226
|
+
|
227
|
+
if (!oWysiwyg) {
|
228
|
+
return this;
|
229
|
+
}
|
230
|
+
|
231
|
+
if (!url || url.length === 0) {
|
232
|
+
return this;
|
233
|
+
}
|
234
|
+
|
235
|
+
selection = oWysiwyg.getRangeText();
|
236
|
+
|
237
|
+
if (selection && selection.length > 0) {
|
238
|
+
if ($.browser.msie) {
|
239
|
+
oWysiwyg.ui.focus();
|
240
|
+
}
|
241
|
+
oWysiwyg.editorDoc.execCommand("unlink", false, null);
|
242
|
+
oWysiwyg.editorDoc.execCommand("createLink", false, url);
|
243
|
+
} else if (oWysiwyg.options.messages.nonSelection) {
|
244
|
+
window.alert(oWysiwyg.options.messages.nonSelection);
|
245
|
+
}
|
246
|
+
return this;
|
247
|
+
});
|
248
|
+
};
|
249
|
+
})(jQuery);
|