Skip to content

Instantly share code, notes, and snippets.

View garryyao's full-sized avatar

Garry garryyao

  • London
View GitHub Profile
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
@garryyao
garryyao / gist:942118
Created April 26, 2011 11:21
BBCode guide
<dl>
<dt>[b]bold[/b]</dt>
<dd>Bold style text, which produces: <strong>bold</strong>
</dd>
<dt>[quote="cite"]quotation text[/quote]</dt>
<dd>Citing and quoting text, which produces: <blockquote><cite>cite</cite><div>quotation text</div></blockquote></dd>
</dl>
@garryyao
garryyao / iframe-dialog-sample
Created August 25, 2011 09:21
CKEditor Iframe dialog sample
/*
* @example An iframe-based dialog with frame window fit dialog size.
*/
( function() {
CKEDITOR.plugins.add( 'iframe-fit-size',
{
requires: [ 'iframedialog' ],
init: function( editor )
{
var height = 480, width = 750;
@garryyao
garryyao / gist:1275587
Created October 10, 2011 15:20
CKEditor custom data filtering
CKEDITOR.replace( 'editor1',
{
on :
{
'pluginsLoaded' : function( evt )
{
// Disallow all heading elements.
evt.editor.dataProcessor.dataFilter.addRules(
{
@garryyao
garryyao / gist:1280590
Created October 12, 2011 08:13
Insert link in editor.
// Insert link (apply link style) to selected html in editor.
var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why.
style.apply( editor.document );
@garryyao
garryyao / gist:1409175
Created November 30, 2011 14:06
Workaround for FF bug on selection lost when hiding the editor
// The below code is for FF only.
var editor = CKEDITOR.appendTo( 'editor1' );
setTimeout( function()
{
var focused = editor.focusManager.hasFocus;
if ( focused )
{
var sel = editor.getSelection();
sel.lock();
@garryyao
garryyao / getIndex
Created January 13, 2012 07:12
getIndex with normalization implementation
function getIndex( normalized )
{
// Attention: getAddress depends on this.$
// getIndex is called on a plain object: { $ : node }
var current = this.$,
index = -1,
isNormalizing;
do
@garryyao
garryyao / editable.js
Created February 8, 2012 04:30
List of editable elements name
// Generate list of editable elements from DTD.
// :npm install underscore
// :node editable.js
var _ = require('underscore');
var X = _.intersection, U = _.union, D = _.difference;
var flow = [ 'a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'blockquote', 'br', 'button', 'canvas', 'cite', 'code', 'command', 'datalist', 'del', 'details', 'dfn', 'div', 'dl', 'em', 'embed', 'fieldset', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hgroup', 'hr', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'keygen', 'label', 'map', 'mark', 'math', 'menu', 'meter', 'nav', 'noscript', 'object', 'ol', 'output', 'p', 'pre', 'progress', 'q', 'ruby', 's', 'samp', 'script', 'section', 'select', 'small', 'span', 'strong', 'style', 'sub', 'sup', 'svg', 'table', 'textarea', 'time', 'u', 'ul', 'var', 'video', 'wbr'],
phrasing = [ 'a', 'abbr', 'area', 'audio', 'b', 'bdi', 'bdo', 'br', 'button', 'canvas', 'cite', 'code', 'command', 'datalist', 'del', 'dfn', 'em', 'embed', 'i',
@garryyao
garryyao / check_selection_collapsed
Created February 21, 2012 07:11
Check text selection is caret
function checkCaretSelection( sel )
{
var ranges = sel.getRanges();
return ranges.length == 1 && ranges[ 0 ].collapsed;
}
@garryyao
garryyao / git-pull-force
Created March 12, 2012 15:26
Git commands for rebase diverged remote branche without a merge.
#!/bin/sh
BRANCH=$1
git checkout $BRANCH
git fetch origin
git merge-base $BRANCH origin/$BRANCH | xargs git reset --hard
git merge origin/$BRANCH --ff-only