forked from rightjs/rightjs-ui
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
248 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* an abstract color-picking tool | ||
* | ||
* Copyright (C) 2010 Nikolay Nemshilov | ||
*/ | ||
Rte.Tool.Color = new Class(Rte.Tool.Options, { | ||
extend: { | ||
COLORS: R([ | ||
// TODO that's ain't no cool hacker's approach! | ||
'000000 444444 666666 999999 cccccc eeeeee f4f4f4 ffffff', | ||
'f24020 f79c33 fff84c 6af244 5ef9fd 0048f7 8950f7 ee5ff8', | ||
'e39e9b f5cba1 fee3a1 bcd3ab a6c3c8 a2c6e5 b1abd3 d0aabc '+ | ||
'd77169 f1b374 fdd675 9cbe83 7ca4ae 74aad8 8983bf bb839f '+ | ||
'cc0100 e79138 f1c332 69a84f 45818e 3d85c6 674ea7 a64d79 '+ | ||
'990000 b45f05 bf9000 38761c 134f5c 0b5394 351b75 751a47 '+ | ||
'660000 783e03 7f6000 264e13 0b333d 063763 1f124c 4c1030' | ||
]) | ||
}, | ||
|
||
/** | ||
* Basic constructor, builds the colors picking panel | ||
* | ||
* @param Rte rte | ||
* @return Rte.Tool.Color this | ||
*/ | ||
initialize: function(rte) { | ||
this.colors = {}; | ||
|
||
this.$super(rte, {}).addClass('color'); | ||
|
||
// building the color picker menu | ||
Rte.Tool.Color.COLORS.each(function(line) { | ||
var group = $E('li', {'class': 'group'}), | ||
list = $E('ul').insertTo(group), | ||
colors = line.split(' '), i = 0, color; | ||
|
||
for (; i < colors.length; i++) { | ||
color = '#' + colors[i]; | ||
|
||
this.items.push( | ||
$E('li', { | ||
html: '•', | ||
style: { | ||
background: color, | ||
color: '#' +( | ||
// calculating an opposite color so the text would be visible | ||
'ffffff'.toInt(16) - colors[i].toInt(16) | ||
).toString(16) | ||
} | ||
}) | ||
.insertTo(list) | ||
.onMousedown(R(this.pick).bind(this)) | ||
); | ||
|
||
this.colors[color] = this.items.last(); | ||
this.colors[color].value = color; | ||
} | ||
|
||
this.options.append(group); | ||
}, this); | ||
|
||
return this; | ||
}, | ||
|
||
/** | ||
* Overloading the original method to check the color | ||
* | ||
* @return boolean check result | ||
*/ | ||
active: function() { | ||
var color = document.queryCommandValue(this.command); | ||
|
||
if (color in this.colors) { | ||
this.display._.style.background = color; | ||
return true; | ||
} else { | ||
this.display._.style.background = 'transparent'; | ||
return false; | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* An abstract tool with an options menu | ||
* | ||
* Copyright (C) 2010 Nikolay Nemshilov | ||
*/ | ||
Rte.Tool.Options = new Class(Rte.Tool, { | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param Rte rte instance | ||
* @param Object key -> value hash | ||
*/ | ||
initialize: function(rte, options) { | ||
this.display = $E('div', {'class': 'display'}); | ||
this.options = $E('ul', {'class': 'options'}); | ||
|
||
this | ||
.$super(rte) | ||
.addClass('with-options') | ||
.append(this.display, this.options); | ||
|
||
this.items = R([]); | ||
|
||
for (var value in options) { | ||
this.items.push($E('li', {html: options[value]})); | ||
this.items.last().insertTo(this.list).value = value; | ||
} | ||
|
||
this.options.onMousedown(R(this.pick).bind(this)); | ||
|
||
// hidding the menu when the user interacts with the document outside of the document | ||
var hide = R(this.options.hide).bind(this.options, null); | ||
|
||
$(document).on({ | ||
mousedown: hide, | ||
keydown: function(event) { | ||
if (event.keyCode === 27) { | ||
hide(); | ||
} | ||
} | ||
}); | ||
|
||
return this; | ||
}, | ||
|
||
// protected | ||
|
||
// handling an option pick | ||
pick: function(event) { | ||
var target = event.stop().target, value = target.value; | ||
|
||
if (value !== undefined) { | ||
this.options.hide(); | ||
this.items.each('removeClass', 'active'); | ||
target.addClass('active'); | ||
this.value = value; | ||
this.exec(); | ||
} | ||
}, | ||
|
||
// toggling the menu on the icon-click | ||
mousedown: function() { | ||
$$('.rui-rte-toolbar div.with-options ul.options') | ||
.without(this.options).each('hide'); | ||
|
||
this.options.toggle('fade', {duration: 'short'}); | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* the 'backcolor' tool | ||
* | ||
* Copyright (C) 2010 Nikolay Nemshilov | ||
*/ | ||
Rte.Tool.Backcolor = new Class(Rte.Tool.Color, { | ||
command: 'backcolor' // 'hiliteColor' | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* the 'forecolor' tool | ||
* | ||
* Copyright (C) 2010 Nikolay Nemshilov | ||
*/ | ||
Rte.Tool.Forecolor = new Class(Rte.Tool.Color, { | ||
command: 'forecolor' | ||
}); |