yellow-text-rails 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module YellowText
2
2
  module Rails
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
@@ -4,464 +4,8 @@
4
4
  * This plugin is created to make text editing
5
5
  * more fun and to make it easy for the editor.
6
6
  *
7
- * Version: 0.3.2
7
+ * Version: 0.4.1
8
8
  * Author: Stefan Vermaas
9
9
  * URL: www.stefanvermaas.nl
10
10
  *
11
- */
12
- (function( $ ) {
13
-
14
- // Define the plugin methods
15
- var methods = {
16
-
17
- // Call the initialization function
18
- init: function( that, options ) {
19
-
20
- // Create the global this element
21
- methods.el = that;
22
-
23
- /**
24
- *
25
- * Settings
26
- * =========================================
27
- * This part of the plugin contains the settings
28
- * that are default. Feel free to override them
29
- * during intialization of the plugin.
30
- *
31
- * For an example, see javascripts/demo.js
32
- *
33
- */
34
- methods.settings = $.extend( {
35
- width : "100%",
36
- height : "300px",
37
- containerClass : "js-editor-container",
38
- buttonsClass : "js-editor-buttons",
39
- iFrameClass : "js-editor-iframe",
40
- cleanOnSubmit : true,
41
- defaultFont : "Helvetica Neue, Helvetica, arial, sans-serief",
42
- defaultFontSize : "1em",
43
- defaultFontColor : "#000000",
44
- defaultActions : "bold, underline, italic, strikethrough, align-left, align-center, align-right, unorderd-list, ordered-list, link, image",
45
-
46
- // Callbacks
47
- isContentChanged : function() {},
48
- setImage : function() {}
49
- }, options);
50
-
51
- // Render the plugin
52
- methods.render();
53
-
54
- // Grap the content and put it in the iframe
55
- methods.setContent();
56
-
57
- // Listen to events and react on them
58
- methods.events();
59
- },
60
-
61
- /**
62
- *
63
- * Render
64
- * =========================================
65
- * This function renders the whole plugin and
66
- * it's only used to build the plugin.
67
- *
68
- */
69
- render: function() {
70
-
71
- // Render the new text editor
72
- methods.createTextEditor();
73
-
74
- // Render the buttons
75
- methods.createButtons();
76
- },
77
-
78
- /**
79
- *
80
- * createTextEditor
81
- * =========================================
82
- * This part of the plugin builds the main
83
- * elements of the new text editor
84
- *
85
- */
86
- createTextEditor: function() {
87
-
88
- // Hide the current text field
89
- $(methods.el).hide();
90
-
91
- // Create a container which will hold or text editor
92
- methods.container = $("<div />").addClass( methods.settings.containerClass ).css({
93
- "float" : "left",
94
- "width" : methods.settings.width,
95
- "border" : "1px solid #ccc"
96
- });
97
-
98
- // Add the container after the element where we bind this plugin too
99
- $(methods.el).after( methods.container );
100
-
101
- // Create the iFrame and append to the previously created container
102
- methods.editor = $("<iframe />").addClass( methods.settings.iFrameClass ).css({
103
- "float" : "left",
104
- "width" : methods.settings.width,
105
- "height" : methods.settings.height,
106
- "border" : "0",
107
- "overflow": "hidden"
108
- }).appendTo( methods.container ).get(0);
109
-
110
- // Make the editor work in all browsers
111
- methods.editor.contentWindow.document.open();
112
- methods.editor.contentWindow.document.close();
113
- methods.editor.contentWindow.document.designMode="on";
114
-
115
- // Set the standard fonts etc
116
- $(methods.editor).contents().find("body").css({
117
- "word-wrap" : "break-word",
118
- "font-family" : methods.settings.defaultFont,
119
- "font-size" : methods.settings.defaultFontSize,
120
- "color" : methods.settings.defaultFontColor
121
- });
122
-
123
- // Add some css to the iFrame
124
- var iFrameCSS = '<style type="text/css">body{padding: 2%;} p { margin: 0; }</style>';
125
- $(methods.editor).contents().find("head").append(iFrameCSS);
126
-
127
- // Build the button container
128
- methods.buttons = $("<div />").addClass( methods.settings.buttonsClass ).css({
129
- "float" : "left",
130
- "width" : methods.settings.width
131
- }).prependTo( methods.container );
132
- },
133
-
134
- /**
135
- *
136
- * Content
137
- * =========================================
138
- * Graps the content from the textarea and puts
139
- * it in the text editor
140
- *
141
- */
142
- setContent: function() {
143
-
144
- // Grap the content of the textarea
145
- var content = $(methods.el).text();
146
-
147
- // Put the content of the textarea into the editor
148
- $( methods.editor ).contents().find("body").append(content);
149
- },
150
-
151
- /**
152
- *
153
- * createButtons
154
- * =========================================
155
- * This part of the plugin build all the buttons
156
- * that are defined by the user or it takes the
157
- * default buttons.
158
- *
159
- */
160
- createButtons: function() {
161
-
162
- // Define the "to make buttons"
163
- var defaultOptions = methods.settings.defaultActions.split(/, ?/);
164
-
165
- // Loop through all the buttons
166
- for( i = 0; i < defaultOptions.length; i++ ) {
167
-
168
- // Create a variable to store the object in
169
- var button;
170
-
171
- // Get the right value
172
- switch( defaultOptions[i] ) {
173
- case "bold" :
174
- button = { content : "b", command : "bold" };
175
- break;
176
- case "underline" :
177
- button = { content : "u", command : "underline" };
178
- break;
179
- case "italic" :
180
- button = { content : "i", command : "italic" };
181
- break;
182
- case "strikethrough" :
183
- button = { content : "s", command : "strikethrough" };
184
- break;
185
- case "align-left" :
186
- button = { content : "left", command : "JustifyLeft" };
187
- break;
188
- case "align-center" :
189
- button = { content : "center", command : "JustifyCenter" };
190
- break;
191
- case "align-right" :
192
- button = { content : "right", command : "JustifyRight" };
193
- break;
194
- case "unorderd-list" :
195
- button = { content : "ul", command : "InsertUnorderedList" };
196
- break;
197
- case "ordered-list" :
198
- button = { content : "ol", command : "InsertOrderedList" };
199
- break;
200
- case "image" :
201
- button = { content : "img", command : "image" };
202
- break;
203
- case "link" :
204
- button = { content : "link", command : "link" };
205
- break;
206
- default :
207
- button = { content : "", command : "" };
208
- }
209
-
210
- // Build the buttons and add before the container
211
- $("<a />")
212
- .addClass( button.command )
213
- .text( button.content )
214
- .attr( "data-command", button.command )
215
- .appendTo( methods.buttons );
216
- }
217
- },
218
-
219
- /**
220
- *
221
- * Events
222
- * =========================================
223
- * Listen to specific events. The events that
224
- * are justed in this plugin are click, keydown
225
- * and submit event
226
- *
227
- * With the click event we can detect a click on
228
- * a button to modify the text.
229
- *
230
- * With the keydown event we can detect or the
231
- * user uses shortkeys for editing text.
232
- *
233
- */
234
- events: function() {
235
-
236
- // Bind to the click event on the buttons
237
- $("." + methods.settings.buttonsClass + " a").on("click", function(e) {
238
-
239
- // React on the button event
240
- methods.buttonClicked( e, this );
241
- });
242
-
243
- // Bind to the keydown event while typing
244
- $( methods.editor ).contents().find("body").on("keydown", function(e) {
245
-
246
- // Check for a specific keycode
247
- if( e.ctrlKey || e.metaKey ) {
248
- methods.shortkey( e, this );
249
- }
250
- });
251
-
252
- // Bind the keyup event, to check for changes
253
- $( methods.editor ).contents().find("body").on("keyup", function(e) {
254
-
255
- // Check or the text is changed
256
- var changed = ( $( methods.editor ).contents().find("body").html() !== $(methods.el).text() ) ? true : false;
257
-
258
- // Call the callback
259
- methods.settings.isContentChanged( changed );
260
- });
261
-
262
- // Bind to the submit event of the form
263
- $( methods.el ).parents("form").on("submit", function(e) {
264
-
265
- // First clean the code
266
- methods.cleanTheCode();
267
-
268
- // Put the content back in the textfield
269
- methods.putContentBack();
270
- });
271
-
272
- },
273
-
274
- /**
275
- *
276
- * buttonClicked
277
- * =========================================
278
- * This function reacts on the fact that a
279
- * button is clicked. Based on the button an
280
- * action will be triggered
281
- *
282
- */
283
- buttonClicked: function( e, that ) {
284
-
285
- // Get the command
286
- var command = $(that).attr("data-command");
287
-
288
- // Focus on the contentWindow
289
- methods.editor.contentWindow.focus();
290
-
291
- // Take an other look at the command and look for the perfect action and execute it
292
- methods.runCMD( command );
293
-
294
- // And focus back again on the contentWindow
295
- methods.editor.contentWindow.focus();
296
- },
297
-
298
- /**
299
- *
300
- * shortkey
301
- * =========================================
302
- * Wanna use a shortkey? This function takes
303
- * care for that. You can quickly edit the text
304
- * by using those shortkeys.
305
- *
306
- * Currently you can use cmd/ctrl + b, cmd/ctrl + i
307
- * and cmd/ctrl + u to make your text bold, italic
308
- * or underlined.
309
- *
310
- */
311
- shortkey: function( e ) {
312
-
313
- // Define command
314
- var command;
315
-
316
- // Focus on the contentWindow
317
- methods.editor.contentWindow.focus();
318
-
319
- // Detect for simple actions their functions
320
- if( e.which === 66 ) {
321
- command = "bold";
322
- } else if( e.which === 73 ) {
323
- command = "italic";
324
- } else if( e.which === 85 ) {
325
- command = "underline";
326
- } else {
327
- command = "";
328
- }
329
-
330
- // Run the command
331
- methods.runCMD( command );
332
-
333
- // And focus back again on the contentWindow
334
- methods.editor.contentWindow.focus();
335
- },
336
-
337
- /**
338
- *
339
- * runCMD
340
- * =========================================
341
- * This is the real deal. This part of the
342
- * script handles the actual commands and it
343
- * can be used by every other function as long
344
- * as it provides a command to execute.
345
- *
346
- */
347
- runCMD: function( cmd ) {
348
-
349
- // Check command for special actions and run it
350
- if( cmd === "image" ) {
351
-
352
- // Check for the insertImage function, this will always be true
353
- if( typeof methods.settings.setImage === "function" ) {
354
- var image = methods.settings.setImage.call();
355
- }
356
-
357
- // Check or a other plugin or CMS added an image to the plugin
358
- var url = ( typeof image !== "undefined" && image.length > 0 ) ? image : prompt("URL (example: http://www.google.com): ");
359
-
360
- // Insert the image in the text editor
361
- return methods.editor.contentWindow.document.execCommand( "InsertImage", false, url);
362
-
363
- } else if( cmd === "link" ) {
364
- var link = prompt("URL (example: http://www.google.com): ");
365
- return methods.editor.contentWindow.document.execCommand( "CreateLink", false, link);
366
- } else {
367
- return methods.editor.contentWindow.document.execCommand( cmd );
368
- }
369
- },
370
-
371
- /**
372
- *
373
- * cleanTheCode
374
- * =========================================
375
- * Now we're cleaning up someone's shit. The
376
- * browsers insert really nasty code ( not semantic )
377
- * in our text editor, but that won't stop us!
378
- *
379
- * We're gonna fight back. This function cleans
380
- * the code and makes it pretty. Just like we want too.
381
- *
382
- */
383
- cleanTheCode: function() {
384
-
385
- // Define the body element
386
- var body = $(methods.editor).contents().find("body");
387
-
388
- // Loop through each div tag and change it to a p tag
389
- body.find("div").each( function() {
390
- // Get the class if avaiable
391
- var hasStyle = ( $(this).attr("style") ) ? true : false;
392
-
393
- // Check or a element is not wrapped
394
- if( $(this).parent("p").not("p") ) {
395
-
396
- // Change the div elements to normal p tags
397
- if( hasStyle ) {
398
- // Wrap the content into p tags with the style
399
- $(this).wrap("<p style=\"" + $(this).attr('style') + "\"></p>");
400
- } else {
401
- // Wrap the content into p tags
402
- $(this).wrap("<p></p>");
403
- }
404
- }
405
-
406
- // Unwrap all the div tags
407
- $(this).contents().unwrap();
408
- });
409
-
410
- // Unwrap all br tags and remove the ugly div tags
411
- body.find("br").unwrap();
412
-
413
- // Get fancy stuff done with the first line
414
- var firstLine = "<p>" + $( body.contents()[0] ).html() + "</p>";
415
-
416
- // Remove the first line
417
- $( body.contents()[0] ).remove();
418
-
419
- // Add the line on the first line
420
- body.prepend( firstLine );
421
- },
422
-
423
- /**
424
- *
425
- * putContentBack
426
- * =========================================
427
- * This function is triggered on the submit
428
- * event and is needed to put the content of
429
- * the texteditor back in the text field
430
- * where the plugin is binded too.
431
- *
432
- */
433
- putContentBack: function() {
434
- // Grap the content of the iframe
435
- var postData = $(methods.editor).contents().find("body").html();
436
-
437
- // Make sure the textarea is empty
438
- $( methods.el ).val( postData );
439
- }
440
- };
441
-
442
-
443
- // Initialize the plugin
444
- $.fn.texteditor = function( method ) {
445
-
446
- // Make sure the text editor can bind to all the HTML elements
447
- return this.each( function() {
448
-
449
- // Check for methods
450
- if ( methods[method] ) {
451
-
452
- // Target a specific function
453
- return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ) );
454
- } else if ( typeof method === 'object' || ! method ) {
455
-
456
- // No specific method is found, just initialize the plugin
457
- return methods.init( this, method );
458
- } else {
459
-
460
- // Method doesn't excist for this plugin
461
- $.error( 'Method ' + method + ' does not exist on jQuery.texteditor' );
462
- }
463
- });
464
-
465
- };
466
-
467
- })( jQuery );
11
+ */(function(e){var t={init:function(n,r){t.el=n;t.settings=e.extend({width:"100%",height:"300px",containerClass:"js-editor-container",buttonsClass:"js-editor-buttons",iFrameClass:"js-editor-iframe",cleanOnSubmit:!0,defaultFont:"Helvetica Neue, Helvetica, arial, sans-serief",defaultFontSize:"1em",defaultFontColor:"#000000",defaultActions:"bold, underline, italic, strikethrough, align-left, align-center, align-right, unordered-list, ordered-list, link, image",isContentChanged:function(){},setImage:function(){}},r);t.render();t.setContent();t.events()},render:function(){t.createTextEditor();t.createButtons()},createTextEditor:function(){e(t.el).hide();t.container=e("<div />").addClass(t.settings.containerClass).css({"float":"left",width:t.settings.width,border:"1px solid #ccc"});e(t.el).after(t.container);t.editor=e("<iframe />").addClass(t.settings.iFrameClass).css({"float":"left",width:t.settings.width,height:t.settings.height,border:"0",overflow:"hidden"}).appendTo(t.container).get(0);t.editor.contentWindow.document.open();t.editor.contentWindow.document.close();t.editor.contentWindow.document.designMode="on";e(t.editor).contents().find("body").css({"word-wrap":"break-word","font-family":t.settings.defaultFont,"font-size":t.settings.defaultFontSize,color:t.settings.defaultFontColor});var n='<style type="text/css">body{padding: 2%;} p { margin: 0; }</style>';e(t.editor).contents().find("head").append(n);t.buttons=e("<div />").addClass(t.settings.buttonsClass).css({"float":"left",width:t.settings.width}).prependTo(t.container)},setContent:function(){var n=e(t.el).text();e(t.editor).contents().find("body").append(n)},createButtons:function(){var n=t.settings.defaultActions.split(/, ?/);for(i=0;i<n.length;i++){var r;switch(n[i]){case"bold":r={content:"b",command:"bold"};break;case"underline":r={content:"u",command:"underline"};break;case"italic":r={content:"i",command:"italic"};break;case"strikethrough":r={content:"s",command:"strikethrough"};break;case"align-left":r={content:"left",command:"JustifyLeft"};break;case"align-center":r={content:"center",command:"JustifyCenter"};break;case"align-right":r={content:"right",command:"JustifyRight"};break;case"unordered-list":r={content:"ul",command:"InsertUnorderedList"};break;case"ordered-list":r={content:"ol",command:"InsertOrderedList"};break;case"image":r={content:"img",command:"image"};break;case"link":r={content:"link",command:"link"};break;default:r={content:"",command:""}}e("<a />").addClass(r.command).text(r.content).attr("data-command",r.command).appendTo(t.buttons)}},events:function(){e("."+t.settings.buttonsClass+" a").on("click",function(e){t.buttonClicked(e,this)});e(t.editor).contents().find("body").on("keydown",function(e){(e.ctrlKey||e.metaKey)&&t.shortkey(e,this)});e(t.editor).contents().find("body").on("keyup",function(n){var r=e(t.editor).contents().find("body").html()!==e(t.el).text()?!0:!1;t.settings.isContentChanged(r)});e(t.el).parents("form").on("submit",function(e){t.cleanTheCode();t.putContentBack()})},buttonClicked:function(n,r){var i=e(r).attr("data-command");t.editor.contentWindow.focus();t.runCMD(i);t.editor.contentWindow.focus()},shortkey:function(e){var n;t.editor.contentWindow.focus();e.which===66?n="bold":e.which===73?n="italic":e.which===85?n="underline":n="";t.runCMD(n);t.editor.contentWindow.focus()},runCMD:function(e){if(e==="image"){if(typeof t.settings.setImage=="function")var n=t.settings.setImage.call();var r=typeof n!="undefined"&&n.length>0?n:prompt("URL (example: http://www.google.com): ");return t.editor.contentWindow.document.execCommand("InsertImage",!1,r)}if(e==="link"){var i=prompt("URL (example: http://www.google.com): ");return t.editor.contentWindow.document.execCommand("CreateLink",!1,i)}return t.editor.contentWindow.document.execCommand(e)},cleanTheCode:function(){var n=e(t.editor).contents().find("body");n.find("div").each(function(){var t=e(this).attr("style")?!0:!1;e(this).parent("p").not("p")&&(t?e(this).wrap('<p style="'+e(this).attr("style")+'"></p>'):e(this).wrap("<p></p>"));e(this).contents().unwrap()});n.find("br").removeAttr("class").unwrap();var r="<p>"+e(n.contents()[0]).html()+"</p>";e(n.contents()[0]).remove();n.prepend(r)},putContentBack:function(){var n=e(t.editor).contents().find("body").html();e(t.el).val(n)}};e.fn.texteditor=function(n){return this.each(function(){if(t[n])return t[n].apply(this,Array.prototype.slice.call(arguments,1));if(typeof n=="object"||!n)return t.init(this,n);e.error("Method "+n+" does not exist on jQuery.texteditor")})}})(jQuery);
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yellow-text-rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stefan Vermaas
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-02-10 00:00:00 Z
18
+ date: 2013-02-22 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: railties