bootstrap-wysihtml5-rails 0.2.12 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,21 +7,10 @@ task 'update' do
7
7
  system("git clone git://github.com/jhollingworth/bootstrap-wysihtml5.git")
8
8
  system("cp bootstrap-wysihtml5/src/bootstrap-wysihtml5.css vendor/assets/stylesheets/bootstrap-wysihtml5.css")
9
9
  system("cp bootstrap-wysihtml5/src/bootstrap-wysihtml5.js vendor/assets/javascripts/bootstrap-wysihtml5.js")
10
- system("cp bootstrap-wysihtml5/lib/js/wysihtml5-0.3.0_rc3.js vendor/assets/javascripts/wysihtml5.js")
10
+ system("cp bootstrap-wysihtml5/lib/js/wysihtml5-0.3.0.js vendor/assets/javascripts/wysihtml5.js")
11
11
  system("git status")
12
12
  end
13
13
 
14
- desc "Build the gem"
15
- task "build" do
16
- system("gem build bootstrap-wysihtml5-rails.gemspec")
17
- end
18
-
19
- desc "Publish the gem"
20
- task 'publish' do
21
- system("gem push bootstrap-wysihtml5-rails-#{BootstrapWysihtml5Rails::Rails::VERSION}.gem")
22
- system("git push")
23
- end
24
-
25
14
  desc "Release a new version"
26
15
  task "release" do
27
16
  system("gem build bootstrap-wysihtml5-rails.gemspec")
@@ -1,5 +1,5 @@
1
1
  module BootstrapWysihtml5Rails
2
2
  module Rails
3
- VERSION = "0.2.12"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license wysihtml5 v0.3.0_rc3
2
+ * @license wysihtml5 v0.3.0
3
3
  * https://github.com/xing/wysihtml5
4
4
  *
5
5
  * Author: Christopher Blum (https://github.com/tiff)
@@ -9,7 +9,7 @@
9
9
  *
10
10
  */
11
11
  var wysihtml5 = {
12
- version: "0.3.0_rc3",
12
+ version: "0.3.0",
13
13
 
14
14
  // namespaces
15
15
  commands: {},
@@ -3557,8 +3557,8 @@ wysihtml5.browser = (function() {
3557
3557
  // When inserting unordered or ordered lists in Firefox, Chrome or Safari, the current selection or line gets
3558
3558
  // converted into a list (<ul><li>...</li></ul>, <ol><li>...</li></ol>)
3559
3559
  // IE and Opera act a bit different here as they convert the entire content of the current block element into a list
3560
- "insertUnorderedList": isIE || isOpera,
3561
- "insertOrderedList": isIE || isOpera
3560
+ "insertUnorderedList": isIE || isOpera || isWebKit,
3561
+ "insertOrderedList": isIE || isOpera || isWebKit
3562
3562
  };
3563
3563
 
3564
3564
  // Firefox throws errors for queryCommandSupported, so we have to build up our own object of supported commands
@@ -4148,18 +4148,38 @@ wysihtml5.dom.convertToList = (function() {
4148
4148
 
4149
4149
  var doc = element.ownerDocument,
4150
4150
  list = _createList(doc, listType),
4151
- childNodes = wysihtml5.lang.array(element.childNodes).get(),
4152
- childNodesLength = childNodes.length,
4151
+ lineBreaks = element.querySelectorAll("br"),
4152
+ lineBreaksLength = lineBreaks.length,
4153
+ childNodes,
4154
+ childNodesLength,
4153
4155
  childNode,
4156
+ lineBreak,
4157
+ parentNode,
4154
4158
  isBlockElement,
4155
4159
  isLineBreak,
4156
4160
  currentListItem,
4157
- i = 0;
4158
- for (; i<childNodesLength; i++) {
4159
- currentListItem = currentListItem || _createListItem(doc, list);
4160
- childNode = childNodes[i];
4161
- isBlockElement = wysihtml5.dom.getStyle("display").from(childNode) === "block";
4162
- isLineBreak = childNode.nodeName === "BR";
4161
+ i;
4162
+
4163
+ // First find <br> at the end of inline elements and move them behind them
4164
+ for (i=0; i<lineBreaksLength; i++) {
4165
+ lineBreak = lineBreaks[i];
4166
+ while ((parentNode = lineBreak.parentNode) && parentNode !== element && parentNode.lastChild === lineBreak) {
4167
+ if (wysihtml5.dom.getStyle("display").from(parentNode) === "block") {
4168
+ parentNode.removeChild(lineBreak);
4169
+ break;
4170
+ }
4171
+ wysihtml5.dom.insert(lineBreak).after(lineBreak.parentNode);
4172
+ }
4173
+ }
4174
+
4175
+ childNodes = wysihtml5.lang.array(element.childNodes).get();
4176
+ childNodesLength = childNodes.length;
4177
+
4178
+ for (i=0; i<childNodesLength; i++) {
4179
+ currentListItem = currentListItem || _createListItem(doc, list);
4180
+ childNode = childNodes[i];
4181
+ isBlockElement = wysihtml5.dom.getStyle("display").from(childNode) === "block";
4182
+ isLineBreak = childNode.nodeName === "BR";
4163
4183
 
4164
4184
  if (isBlockElement) {
4165
4185
  // Append blockElement to current <li> if empty, otherwise create a new one
@@ -4208,7 +4228,7 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
4208
4228
  length = attributesToCopy.length;
4209
4229
  for (; i<length; i++) {
4210
4230
  attribute = attributesToCopy[i];
4211
- if (elementToCopyFrom[attribute]) {
4231
+ if (typeof(elementToCopyFrom[attribute]) !== "undefined" && elementToCopyFrom[attribute] !== "") {
4212
4232
  elementToCopyTo[attribute] = elementToCopyFrom[attribute];
4213
4233
  }
4214
4234
  }
@@ -5242,7 +5262,7 @@ wysihtml5.dom.replaceWithChildNodes = function(node) {
5242
5262
 
5243
5263
  var doc = list.ownerDocument,
5244
5264
  fragment = doc.createDocumentFragment(),
5245
- previousSibling = list.previousSibling,
5265
+ previousSibling = list.previousElementSibling || list.previousSibling,
5246
5266
  firstChild,
5247
5267
  lastChild,
5248
5268
  isLastChild,
@@ -6762,21 +6782,23 @@ wysihtml5.Commands = Base.extend(
6762
6782
  exec: function(command, value) {
6763
6783
  var obj = wysihtml5.commands[command],
6764
6784
  args = wysihtml5.lang.array(arguments).get(),
6765
- method = obj && obj.exec;
6785
+ method = obj && obj.exec,
6786
+ result = null;
6766
6787
 
6767
6788
  this.editor.fire("beforecommand:composer");
6768
6789
 
6769
6790
  if (method) {
6770
6791
  args.unshift(this.composer);
6771
- return method.apply(obj, args);
6792
+ result = method.apply(obj, args);
6772
6793
  } else {
6773
6794
  try {
6774
6795
  // try/catch for buggy firefox
6775
- return this.doc.execCommand(command, false, value);
6796
+ result = this.doc.execCommand(command, false, value);
6776
6797
  } catch(e) {}
6777
6798
  }
6778
6799
 
6779
6800
  this.editor.fire("aftercommand:composer");
6801
+ return result;
6780
6802
  },
6781
6803
 
6782
6804
  /**
@@ -6828,7 +6850,8 @@ wysihtml5.Commands = Base.extend(
6828
6850
  }
6829
6851
  }
6830
6852
  }
6831
- });(function(wysihtml5) {
6853
+ });
6854
+ (function(wysihtml5) {
6832
6855
  var undef;
6833
6856
 
6834
6857
  wysihtml5.commands.bold = {
@@ -7472,55 +7495,52 @@ wysihtml5.Commands = Base.extend(
7472
7495
 
7473
7496
  wysihtml5.commands.insertOrderedList = {
7474
7497
  exec: function(composer, command) {
7475
- var doc = composer.doc,
7476
- selectedNode,
7498
+ var doc = composer.doc,
7499
+ selectedNode = composer.selection.getSelectedNode(),
7500
+ list = wysihtml5.dom.getParentElement(selectedNode, { nodeName: "OL" }),
7501
+ otherList = wysihtml5.dom.getParentElement(selectedNode, { nodeName: "UL" }),
7502
+ tempClassName = "_wysihtml5-temp-" + new Date().getTime(),
7477
7503
  isEmpty,
7478
- tempElement,
7479
- list;
7480
-
7504
+ tempElement;
7505
+
7481
7506
  if (composer.commands.support(command)) {
7482
7507
  doc.execCommand(command, false, null);
7508
+ return;
7509
+ }
7510
+
7511
+ if (list) {
7512
+ // Unwrap list
7513
+ // <ol><li>foo</li><li>bar</li></ol>
7514
+ // becomes:
7515
+ // foo<br>bar<br>
7516
+ composer.selection.executeAndRestoreSimple(function() {
7517
+ wysihtml5.dom.resolveList(list);
7518
+ });
7519
+ } else if (otherList) {
7520
+ // Turn an unordered list into an ordered list
7521
+ // <ul><li>foo</li><li>bar</li></ul>
7522
+ // becomes:
7523
+ // <ol><li>foo</li><li>bar</li></ol>
7524
+ composer.selection.executeAndRestoreSimple(function() {
7525
+ wysihtml5.dom.renameElement(otherList, "ol");
7526
+ });
7483
7527
  } else {
7484
- selectedNode = composer.selection.getSelectedNode();
7485
- list = wysihtml5.dom.getParentElement(selectedNode, { nodeName: ["UL", "OL"] }, 4);
7486
- if (!list) {
7487
- tempElement = doc.createElement("span");
7488
- composer.selection.surround(tempElement);
7489
- isEmpty = tempElement.innerHTML === "" || tempElement.innerHTML === wysihtml5.INVISIBLE_SPACE;
7490
- composer.selection.executeAndRestoreSimple(function() {
7491
- list = wysihtml5.dom.convertToList(tempElement, "ol");
7492
- });
7493
-
7494
- if (isEmpty) {
7495
- composer.selection.selectNode(list.querySelector("li"));
7496
- }
7497
- return;
7498
- }
7499
-
7528
+ // Create list
7529
+ composer.commands.exec("formatBlock", "div", tempClassName);
7530
+ tempElement = doc.querySelector("." + tempClassName);
7531
+ isEmpty = tempElement.innerHTML === "" || tempElement.innerHTML === wysihtml5.INVISIBLE_SPACE;
7500
7532
  composer.selection.executeAndRestoreSimple(function() {
7501
- if (list.nodeName === "OL") {
7502
- // Unwrap list
7503
- // <ol><li>foo</li><li>bar</li></ol>
7504
- // becomes:
7505
- // foo<br>bar<br>
7506
- wysihtml5.dom.resolveList(list);
7507
- } else if (list.nodeName === "UL" || list.nodeName === "MENU") {
7508
- // Turn an unordered list into an ordered list
7509
- // <ul><li>foo</li><li>bar</li></ul>
7510
- // becomes:
7511
- // <ol><li>foo</li><li>bar</li></ol>
7512
- wysihtml5.dom.renameElement(list, "ol");
7513
- }
7533
+ list = wysihtml5.dom.convertToList(tempElement, "ol");
7514
7534
  });
7535
+ if (isEmpty) {
7536
+ composer.selection.selectNode(list.querySelector("li"));
7537
+ }
7515
7538
  }
7516
7539
  },
7517
-
7518
- state: function(composer, command) {
7519
- try {
7520
- return composer.doc.queryCommandState(command);
7521
- } catch(e) {
7522
- return false;
7523
- }
7540
+
7541
+ state: function(composer) {
7542
+ var selectedNode = composer.selection.getSelectedNode();
7543
+ return wysihtml5.dom.getParentElement(selectedNode, { nodeName: "OL" });
7524
7544
  },
7525
7545
 
7526
7546
  value: function() {
@@ -7532,56 +7552,52 @@ wysihtml5.Commands = Base.extend(
7532
7552
 
7533
7553
  wysihtml5.commands.insertUnorderedList = {
7534
7554
  exec: function(composer, command) {
7535
- var doc = composer.doc,
7536
- selectedNode,
7555
+ var doc = composer.doc,
7556
+ selectedNode = composer.selection.getSelectedNode(),
7557
+ list = wysihtml5.dom.getParentElement(selectedNode, { nodeName: "UL" }),
7558
+ otherList = wysihtml5.dom.getParentElement(selectedNode, { nodeName: "OL" }),
7559
+ tempClassName = "_wysihtml5-temp-" + new Date().getTime(),
7537
7560
  isEmpty,
7538
- tempElement,
7539
- list;
7540
-
7561
+ tempElement;
7562
+
7541
7563
  if (composer.commands.support(command)) {
7542
7564
  doc.execCommand(command, false, null);
7565
+ return;
7566
+ }
7567
+
7568
+ if (list) {
7569
+ // Unwrap list
7570
+ // <ul><li>foo</li><li>bar</li></ul>
7571
+ // becomes:
7572
+ // foo<br>bar<br>
7573
+ composer.selection.executeAndRestoreSimple(function() {
7574
+ wysihtml5.dom.resolveList(list);
7575
+ });
7576
+ } else if (otherList) {
7577
+ // Turn an ordered list into an unordered list
7578
+ // <ol><li>foo</li><li>bar</li></ol>
7579
+ // becomes:
7580
+ // <ul><li>foo</li><li>bar</li></ul>
7581
+ composer.selection.executeAndRestoreSimple(function() {
7582
+ wysihtml5.dom.renameElement(otherList, "ul");
7583
+ });
7543
7584
  } else {
7544
- selectedNode = composer.selection.getSelectedNode();
7545
- list = wysihtml5.dom.getParentElement(selectedNode, { nodeName: ["UL", "OL"] });
7546
-
7547
- if (!list) {
7548
- tempElement = doc.createElement("span");
7549
- composer.selection.surround(tempElement);
7550
- isEmpty = tempElement.innerHTML === "" || tempElement.innerHTML === wysihtml5.INVISIBLE_SPACE;
7551
- composer.selection.executeAndRestoreSimple(function() {
7552
- list = wysihtml5.dom.convertToList(tempElement, "ul");
7553
- });
7554
-
7555
- if (isEmpty) {
7556
- composer.selection.selectNode(list.querySelector("li"));
7557
- }
7558
- return;
7559
- }
7560
-
7585
+ // Create list
7586
+ composer.commands.exec("formatBlock", "div", tempClassName);
7587
+ tempElement = doc.querySelector("." + tempClassName);
7588
+ isEmpty = tempElement.innerHTML === "" || tempElement.innerHTML === wysihtml5.INVISIBLE_SPACE;
7561
7589
  composer.selection.executeAndRestoreSimple(function() {
7562
- if (list.nodeName === "UL") {
7563
- // Unwrap list
7564
- // <ul><li>foo</li><li>bar</li></ul>
7565
- // becomes:
7566
- // foo<br>bar<br>
7567
- wysihtml5.dom.resolveList(list);
7568
- } else if (list.nodeName === "OL" || list.nodeName === "MENU") {
7569
- // Turn an ordered list into an unordered list
7570
- // <ol><li>foo</li><li>bar</li></ol>
7571
- // becomes:
7572
- // <ul><li>foo</li><li>bar</li></ul>
7573
- wysihtml5.dom.renameElement(list, "ul");
7574
- }
7590
+ list = wysihtml5.dom.convertToList(tempElement, "ul");
7575
7591
  });
7592
+ if (isEmpty) {
7593
+ composer.selection.selectNode(list.querySelector("li"));
7594
+ }
7576
7595
  }
7577
7596
  },
7578
-
7579
- state: function(composer, command) {
7580
- try {
7581
- return composer.doc.queryCommandState(command);
7582
- } catch(e) {
7583
- return false;
7584
- }
7597
+
7598
+ state: function(composer) {
7599
+ var selectedNode = composer.selection.getSelectedNode();
7600
+ return wysihtml5.dom.getParentElement(selectedNode, { nodeName: "UL" });
7585
7601
  },
7586
7602
 
7587
7603
  value: function() {
@@ -8543,7 +8559,7 @@ wysihtml5.views.View = Base.extend(
8543
8559
  dom.observe(element, "keydown", function(event) {
8544
8560
  var keyCode = event.keyCode,
8545
8561
  command = shortcuts[keyCode];
8546
- if ((event.ctrlKey || event.metaKey) && command) {
8562
+ if ((event.ctrlKey || event.metaKey) && !event.altKey && command) {
8547
8563
  that.commands.exec(command);
8548
8564
  event.preventDefault();
8549
8565
  }
@@ -8581,9 +8597,11 @@ wysihtml5.views.View = Base.extend(
8581
8597
  if (nodeName !== "A" && nodeName !== "IMG") {
8582
8598
  return;
8583
8599
  }
8584
-
8585
- title = titlePrefixes[nodeName] + (target.getAttribute("href") || target.getAttribute("src"));
8586
- target.setAttribute("title", title);
8600
+ var hasTitle = target.hasAttribute("title");
8601
+ if(!hasTitle){
8602
+ title = titlePrefixes[nodeName] + (target.getAttribute("href") || target.getAttribute("src"));
8603
+ target.setAttribute("title", title);
8604
+ }
8587
8605
  });
8588
8606
  };
8589
8607
  })(wysihtml5);/**
@@ -9047,6 +9065,7 @@ wysihtml5.views.Textarea = wysihtml5.views.View.extend(
9047
9065
  var CLASS_NAME_COMMAND_DISABLED = "wysihtml5-command-disabled",
9048
9066
  CLASS_NAME_COMMANDS_DISABLED = "wysihtml5-commands-disabled",
9049
9067
  CLASS_NAME_COMMAND_ACTIVE = "wysihtml5-command-active",
9068
+ CLASS_NAME_ACTION_ACTIVE = "wysihtml5-action-active",
9050
9069
  dom = wysihtml5.dom;
9051
9070
 
9052
9071
  wysihtml5.toolbar.Toolbar = Base.extend(
@@ -9071,11 +9090,12 @@ wysihtml5.views.Textarea = wysihtml5.views.View.extend(
9071
9090
  },
9072
9091
 
9073
9092
  _getLinks: function(type) {
9074
- var links = this[type + "Links"] = wysihtml5.lang.array(this.container.querySelectorAll("a[data-wysihtml5-" + type + "]")).get(),
9093
+ var links = this[type + "Links"] = wysihtml5.lang.array(this.container.querySelectorAll("[data-wysihtml5-" + type + "]")).get(),
9075
9094
  length = links.length,
9076
9095
  i = 0,
9077
9096
  mapping = this[type + "Mapping"] = {},
9078
9097
  link,
9098
+ group,
9079
9099
  name,
9080
9100
  value,
9081
9101
  dialog;
@@ -9083,10 +9103,12 @@ wysihtml5.views.Textarea = wysihtml5.views.View.extend(
9083
9103
  link = links[i];
9084
9104
  name = link.getAttribute("data-wysihtml5-" + type);
9085
9105
  value = link.getAttribute("data-wysihtml5-" + type + "-value");
9106
+ group = this.container.querySelector("[data-wysihtml5-" + type + "-group='" + name + "']");
9086
9107
  dialog = this._getDialog(link, name);
9087
9108
 
9088
9109
  mapping[name + ":" + value] = {
9089
9110
  link: link,
9111
+ group: group,
9090
9112
  name: name,
9091
9113
  value: value,
9092
9114
  dialog: dialog,
@@ -9234,8 +9256,10 @@ wysihtml5.views.Textarea = wysihtml5.views.View.extend(
9234
9256
  _updateLinkStates: function() {
9235
9257
  var element = this.composer.element,
9236
9258
  commandMapping = this.commandMapping,
9259
+ actionMapping = this.actionMapping,
9237
9260
  i,
9238
9261
  state,
9262
+ action,
9239
9263
  command;
9240
9264
  // every millisecond counts... this is executed quite often
9241
9265
  for (i in commandMapping) {
@@ -9243,6 +9267,9 @@ wysihtml5.views.Textarea = wysihtml5.views.View.extend(
9243
9267
  if (this.commandsDisabled) {
9244
9268
  state = false;
9245
9269
  dom.removeClass(command.link, CLASS_NAME_COMMAND_ACTIVE);
9270
+ if (command.group) {
9271
+ dom.removeClass(command.group, CLASS_NAME_COMMAND_ACTIVE);
9272
+ }
9246
9273
  if (command.dialog) {
9247
9274
  command.dialog.hide();
9248
9275
  }
@@ -9256,6 +9283,9 @@ wysihtml5.views.Textarea = wysihtml5.views.View.extend(
9256
9283
  state = state.length === 1 ? state[0] : true;
9257
9284
  }
9258
9285
  dom.removeClass(command.link, CLASS_NAME_COMMAND_DISABLED);
9286
+ if (command.group) {
9287
+ dom.removeClass(command.group, CLASS_NAME_COMMAND_DISABLED);
9288
+ }
9259
9289
  }
9260
9290
 
9261
9291
  if (command.state === state) {
@@ -9265,6 +9295,9 @@ wysihtml5.views.Textarea = wysihtml5.views.View.extend(
9265
9295
  command.state = state;
9266
9296
  if (state) {
9267
9297
  dom.addClass(command.link, CLASS_NAME_COMMAND_ACTIVE);
9298
+ if (command.group) {
9299
+ dom.addClass(command.group, CLASS_NAME_COMMAND_ACTIVE);
9300
+ }
9268
9301
  if (command.dialog) {
9269
9302
  if (typeof(state) === "object") {
9270
9303
  command.dialog.show(state);
@@ -9274,11 +9307,27 @@ wysihtml5.views.Textarea = wysihtml5.views.View.extend(
9274
9307
  }
9275
9308
  } else {
9276
9309
  dom.removeClass(command.link, CLASS_NAME_COMMAND_ACTIVE);
9310
+ if (command.group) {
9311
+ dom.removeClass(command.group, CLASS_NAME_COMMAND_ACTIVE);
9312
+ }
9277
9313
  if (command.dialog) {
9278
9314
  command.dialog.hide();
9279
9315
  }
9280
9316
  }
9281
9317
  }
9318
+
9319
+ for (i in actionMapping) {
9320
+ action = actionMapping[i];
9321
+
9322
+ if (action.name === "change_view") {
9323
+ action.state = this.editor.currentView === this.editor.textarea;
9324
+ if (action.state) {
9325
+ dom.addClass(action.link, CLASS_NAME_ACTION_ACTIVE);
9326
+ } else {
9327
+ dom.removeClass(action.link, CLASS_NAME_ACTION_ACTIVE);
9328
+ }
9329
+ }
9330
+ }
9282
9331
  },
9283
9332
 
9284
9333
  show: function() {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-wysihtml5-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-23 00:00:00.000000000 Z
12
+ date: 2012-07-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -94,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  segments:
96
96
  - 0
97
- hash: 102149792187236316
97
+ hash: -599525991395027129
98
98
  required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  none: false
100
100
  requirements:
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  segments:
105
105
  - 0
106
- hash: 102149792187236316
106
+ hash: -599525991395027129
107
107
  requirements: []
108
108
  rubyforge_project:
109
109
  rubygems_version: 1.8.24