Created
January 29, 2015 09:38
-
-
Save janfoeh/4422aec7ae1b5c5718f4 to your computer and use it in GitHub Desktop.
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
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.scribePluginIntelligentUnlinkCommand=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | |
var baseIndexOf = require('../internals/baseIndexOf'), forOwn = require('../objects/forOwn'), isArray = require('../objects/isArray'), isString = require('../objects/isString'); | |
var nativeMax = Math.max; | |
function contains(collection, target, fromIndex) { | |
var index = -1, indexOf = baseIndexOf, length = collection ? collection.length : 0, result = false; | |
fromIndex = (fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex) || 0; | |
if (isArray(collection)) { | |
result = indexOf(collection, target, fromIndex) > -1; | |
} else if (typeof length == 'number') { | |
result = (isString(collection) ? collection.indexOf(target, fromIndex) : indexOf(collection, target, fromIndex)) > -1; | |
} else { | |
forOwn(collection, function (value) { | |
if (++index >= fromIndex) { | |
return !(result = value === target); | |
} | |
}); | |
} | |
return result; | |
} | |
module.exports = contains; | |
},{"../internals/baseIndexOf":7,"../objects/forOwn":14,"../objects/isArray":15,"../objects/isString":18}],2:[function(require,module,exports){ | |
var createWrapper = require('../internals/createWrapper'), slice = require('../internals/slice'); | |
function bind(func, thisArg) { | |
return arguments.length > 2 ? createWrapper(func, 17, slice(arguments, 2), null, thisArg) : createWrapper(func, 1, null, null, thisArg); | |
} | |
module.exports = bind; | |
},{"../internals/createWrapper":8,"../internals/slice":13}],3:[function(require,module,exports){ | |
var baseCreate = require('./baseCreate'), isObject = require('../objects/isObject'), setBindData = require('./setBindData'), slice = require('./slice'); | |
var arrayRef = []; | |
var push = arrayRef.push; | |
function baseBind(bindData) { | |
var func = bindData[0], partialArgs = bindData[2], thisArg = bindData[4]; | |
function bound() { | |
if (partialArgs) { | |
var args = slice(partialArgs); | |
push.apply(args, arguments); | |
} | |
if (this instanceof bound) { | |
var thisBinding = baseCreate(func.prototype), result = func.apply(thisBinding, args || arguments); | |
return isObject(result) ? result : thisBinding; | |
} | |
return func.apply(thisArg, args || arguments); | |
} | |
setBindData(bound, bindData); | |
return bound; | |
} | |
module.exports = baseBind; | |
},{"../objects/isObject":17,"./baseCreate":4,"./setBindData":11,"./slice":13}],4:[function(require,module,exports){ | |
var isNative = require('./isNative'), isObject = require('../objects/isObject'), noop = require('../utilities/noop'); | |
var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate; | |
function baseCreate(prototype, properties) { | |
return isObject(prototype) ? nativeCreate(prototype) : {}; | |
} | |
if (!nativeCreate) { | |
baseCreate = function () { | |
function Object() { | |
} | |
return function (prototype) { | |
if (isObject(prototype)) { | |
Object.prototype = prototype; | |
var result = new Object(); | |
Object.prototype = null; | |
} | |
return result || window.Object(); | |
}; | |
}(); | |
} | |
module.exports = baseCreate; | |
},{"../objects/isObject":17,"../utilities/noop":22,"./isNative":9}],5:[function(require,module,exports){ | |
var bind = require('../functions/bind'), identity = require('../utilities/identity'), setBindData = require('./setBindData'), support = require('../support'); | |
var reFuncName = /^\s*function[ \n\r\t]+\w/; | |
var reThis = /\bthis\b/; | |
var fnToString = Function.prototype.toString; | |
function baseCreateCallback(func, thisArg, argCount) { | |
if (typeof func != 'function') { | |
return identity; | |
} | |
if (typeof thisArg == 'undefined' || !('prototype' in func)) { | |
return func; | |
} | |
var bindData = func.__bindData__; | |
if (typeof bindData == 'undefined') { | |
if (support.funcNames) { | |
bindData = !func.name; | |
} | |
bindData = bindData || !support.funcDecomp; | |
if (!bindData) { | |
var source = fnToString.call(func); | |
if (!support.funcNames) { | |
bindData = !reFuncName.test(source); | |
} | |
if (!bindData) { | |
bindData = reThis.test(source); | |
setBindData(func, bindData); | |
} | |
} | |
} | |
if (bindData === false || bindData !== true && bindData[1] & 1) { | |
return func; | |
} | |
switch (argCount) { | |
case 1: | |
return function (value) { | |
return func.call(thisArg, value); | |
}; | |
case 2: | |
return function (a, b) { | |
return func.call(thisArg, a, b); | |
}; | |
case 3: | |
return function (value, index, collection) { | |
return func.call(thisArg, value, index, collection); | |
}; | |
case 4: | |
return function (accumulator, value, index, collection) { | |
return func.call(thisArg, accumulator, value, index, collection); | |
}; | |
} | |
return bind(func, thisArg); | |
} | |
module.exports = baseCreateCallback; | |
},{"../functions/bind":2,"../support":20,"../utilities/identity":21,"./setBindData":11}],6:[function(require,module,exports){ | |
var baseCreate = require('./baseCreate'), isObject = require('../objects/isObject'), setBindData = require('./setBindData'), slice = require('./slice'); | |
var arrayRef = []; | |
var push = arrayRef.push; | |
function baseCreateWrapper(bindData) { | |
var func = bindData[0], bitmask = bindData[1], partialArgs = bindData[2], partialRightArgs = bindData[3], thisArg = bindData[4], arity = bindData[5]; | |
var isBind = bitmask & 1, isBindKey = bitmask & 2, isCurry = bitmask & 4, isCurryBound = bitmask & 8, key = func; | |
function bound() { | |
var thisBinding = isBind ? thisArg : this; | |
if (partialArgs) { | |
var args = slice(partialArgs); | |
push.apply(args, arguments); | |
} | |
if (partialRightArgs || isCurry) { | |
args || (args = slice(arguments)); | |
if (partialRightArgs) { | |
push.apply(args, partialRightArgs); | |
} | |
if (isCurry && args.length < arity) { | |
bitmask |= 16 & ~32; | |
return baseCreateWrapper([ | |
func, | |
isCurryBound ? bitmask : bitmask & ~3, | |
args, | |
null, | |
thisArg, | |
arity | |
]); | |
} | |
} | |
args || (args = arguments); | |
if (isBindKey) { | |
func = thisBinding[key]; | |
} | |
if (this instanceof bound) { | |
thisBinding = baseCreate(func.prototype); | |
var result = func.apply(thisBinding, args); | |
return isObject(result) ? result : thisBinding; | |
} | |
return func.apply(thisBinding, args); | |
} | |
setBindData(bound, bindData); | |
return bound; | |
} | |
module.exports = baseCreateWrapper; | |
},{"../objects/isObject":17,"./baseCreate":4,"./setBindData":11,"./slice":13}],7:[function(require,module,exports){ | |
function baseIndexOf(array, value, fromIndex) { | |
var index = (fromIndex || 0) - 1, length = array ? array.length : 0; | |
while (++index < length) { | |
if (array[index] === value) { | |
return index; | |
} | |
} | |
return -1; | |
} | |
module.exports = baseIndexOf; | |
},{}],8:[function(require,module,exports){ | |
var baseBind = require('./baseBind'), baseCreateWrapper = require('./baseCreateWrapper'), isFunction = require('../objects/isFunction'), slice = require('./slice'); | |
var arrayRef = []; | |
var push = arrayRef.push, unshift = arrayRef.unshift; | |
function createWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { | |
var isBind = bitmask & 1, isBindKey = bitmask & 2, isCurry = bitmask & 4, isCurryBound = bitmask & 8, isPartial = bitmask & 16, isPartialRight = bitmask & 32; | |
if (!isBindKey && !isFunction(func)) { | |
throw new TypeError(); | |
} | |
if (isPartial && !partialArgs.length) { | |
bitmask &= ~16; | |
isPartial = partialArgs = false; | |
} | |
if (isPartialRight && !partialRightArgs.length) { | |
bitmask &= ~32; | |
isPartialRight = partialRightArgs = false; | |
} | |
var bindData = func && func.__bindData__; | |
if (bindData && bindData !== true) { | |
bindData = slice(bindData); | |
if (bindData[2]) { | |
bindData[2] = slice(bindData[2]); | |
} | |
if (bindData[3]) { | |
bindData[3] = slice(bindData[3]); | |
} | |
if (isBind && !(bindData[1] & 1)) { | |
bindData[4] = thisArg; | |
} | |
if (!isBind && bindData[1] & 1) { | |
bitmask |= 8; | |
} | |
if (isCurry && !(bindData[1] & 4)) { | |
bindData[5] = arity; | |
} | |
if (isPartial) { | |
push.apply(bindData[2] || (bindData[2] = []), partialArgs); | |
} | |
if (isPartialRight) { | |
unshift.apply(bindData[3] || (bindData[3] = []), partialRightArgs); | |
} | |
bindData[1] |= bitmask; | |
return createWrapper.apply(null, bindData); | |
} | |
var creater = bitmask == 1 || bitmask === 17 ? baseBind : baseCreateWrapper; | |
return creater([ | |
func, | |
bitmask, | |
partialArgs, | |
partialRightArgs, | |
thisArg, | |
arity | |
]); | |
} | |
module.exports = createWrapper; | |
},{"../objects/isFunction":16,"./baseBind":3,"./baseCreateWrapper":6,"./slice":13}],9:[function(require,module,exports){ | |
var objectProto = Object.prototype; | |
var toString = objectProto.toString; | |
var reNative = RegExp('^' + String(toString).replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/toString| for [^\]]+/g, '.*?') + '$'); | |
function isNative(value) { | |
return typeof value == 'function' && reNative.test(value); | |
} | |
module.exports = isNative; | |
},{}],10:[function(require,module,exports){ | |
var objectTypes = { | |
'boolean': false, | |
'function': true, | |
'object': true, | |
'number': false, | |
'string': false, | |
'undefined': false | |
}; | |
module.exports = objectTypes; | |
},{}],11:[function(require,module,exports){ | |
var isNative = require('./isNative'), noop = require('../utilities/noop'); | |
var descriptor = { | |
'configurable': false, | |
'enumerable': false, | |
'value': null, | |
'writable': false | |
}; | |
var defineProperty = function () { | |
try { | |
var o = {}, func = isNative(func = Object.defineProperty) && func, result = func(o, o, o) && func; | |
} catch (e) { | |
} | |
return result; | |
}(); | |
var setBindData = !defineProperty ? noop : function (func, value) { | |
descriptor.value = value; | |
defineProperty(func, '__bindData__', descriptor); | |
}; | |
module.exports = setBindData; | |
},{"../utilities/noop":22,"./isNative":9}],12:[function(require,module,exports){ | |
var objectTypes = require('./objectTypes'); | |
var objectProto = Object.prototype; | |
var hasOwnProperty = objectProto.hasOwnProperty; | |
var shimKeys = function (object) { | |
var index, iterable = object, result = []; | |
if (!iterable) | |
return result; | |
if (!objectTypes[typeof object]) | |
return result; | |
for (index in iterable) { | |
if (hasOwnProperty.call(iterable, index)) { | |
result.push(index); | |
} | |
} | |
return result; | |
}; | |
module.exports = shimKeys; | |
},{"./objectTypes":10}],13:[function(require,module,exports){ | |
function slice(array, start, end) { | |
start || (start = 0); | |
if (typeof end == 'undefined') { | |
end = array ? array.length : 0; | |
} | |
var index = -1, length = end - start || 0, result = Array(length < 0 ? 0 : length); | |
while (++index < length) { | |
result[index] = array[start + index]; | |
} | |
return result; | |
} | |
module.exports = slice; | |
},{}],14:[function(require,module,exports){ | |
var baseCreateCallback = require('../internals/baseCreateCallback'), keys = require('./keys'), objectTypes = require('../internals/objectTypes'); | |
var forOwn = function (collection, callback, thisArg) { | |
var index, iterable = collection, result = iterable; | |
if (!iterable) | |
return result; | |
if (!objectTypes[typeof iterable]) | |
return result; | |
callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3); | |
var ownIndex = -1, ownProps = objectTypes[typeof iterable] && keys(iterable), length = ownProps ? ownProps.length : 0; | |
while (++ownIndex < length) { | |
index = ownProps[ownIndex]; | |
if (callback(iterable[index], index, collection) === false) | |
return result; | |
} | |
return result; | |
}; | |
module.exports = forOwn; | |
},{"../internals/baseCreateCallback":5,"../internals/objectTypes":10,"./keys":19}],15:[function(require,module,exports){ | |
var isNative = require('../internals/isNative'); | |
var arrayClass = '[object Array]'; | |
var objectProto = Object.prototype; | |
var toString = objectProto.toString; | |
var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray; | |
var isArray = nativeIsArray || function (value) { | |
return value && typeof value == 'object' && typeof value.length == 'number' && toString.call(value) == arrayClass || false; | |
}; | |
module.exports = isArray; | |
},{"../internals/isNative":9}],16:[function(require,module,exports){ | |
function isFunction(value) { | |
return typeof value == 'function'; | |
} | |
module.exports = isFunction; | |
},{}],17:[function(require,module,exports){ | |
var objectTypes = require('../internals/objectTypes'); | |
function isObject(value) { | |
return !!(value && objectTypes[typeof value]); | |
} | |
module.exports = isObject; | |
},{"../internals/objectTypes":10}],18:[function(require,module,exports){ | |
var stringClass = '[object String]'; | |
var objectProto = Object.prototype; | |
var toString = objectProto.toString; | |
function isString(value) { | |
return typeof value == 'string' || value && typeof value == 'object' && toString.call(value) == stringClass || false; | |
} | |
module.exports = isString; | |
},{}],19:[function(require,module,exports){ | |
var isNative = require('../internals/isNative'), isObject = require('./isObject'), shimKeys = require('../internals/shimKeys'); | |
var nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys; | |
var keys = !nativeKeys ? shimKeys : function (object) { | |
if (!isObject(object)) { | |
return []; | |
} | |
return nativeKeys(object); | |
}; | |
module.exports = keys; | |
},{"../internals/isNative":9,"../internals/shimKeys":12,"./isObject":17}],20:[function(require,module,exports){ | |
var isNative = require('./internals/isNative'); | |
var reThis = /\bthis\b/; | |
var support = {}; | |
support.funcDecomp = !isNative(window.WinRTError) && reThis.test(function () { | |
return this; | |
}); | |
support.funcNames = typeof Function.name == 'string'; | |
module.exports = support; | |
},{"./internals/isNative":9}],21:[function(require,module,exports){ | |
function identity(value) { | |
return value; | |
} | |
module.exports = identity; | |
},{}],22:[function(require,module,exports){ | |
function noop() { | |
} | |
module.exports = noop; | |
},{}],23:[function(require,module,exports){ | |
var contains = require('lodash-amd/modern/collections/contains'); | |
'use strict'; | |
var blockElementNames = [ | |
'P', | |
'LI', | |
'DIV', | |
'BLOCKQUOTE', | |
'UL', | |
'OL', | |
'H1', | |
'H2', | |
'H3', | |
'H4', | |
'H5', | |
'H6' | |
]; | |
function isBlockElement(node) { | |
return contains(blockElementNames, node.nodeName); | |
} | |
function isSelectionMarkerNode(node) { | |
return node.nodeType === Node.ELEMENT_NODE && node.className === 'scribe-marker'; | |
} | |
function unwrap(node, childNode) { | |
while (childNode.childNodes.length > 0) { | |
node.insertBefore(childNode.childNodes[0], childNode); | |
} | |
node.removeChild(childNode); | |
} | |
module.exports = { | |
isBlockElement: isBlockElement, | |
isSelectionMarkerNode: isSelectionMarkerNode, | |
unwrap: unwrap | |
}; | |
},{"lodash-amd/modern/collections/contains":1}],24:[function(require,module,exports){ | |
var element = require('scribe-common/src/element'); | |
'use strict'; | |
module.exports = function () { | |
return function (scribe) { | |
var unlinkCommand = new scribe.api.Command('unlink'); | |
unlinkCommand.execute = function () { | |
var selection = new scribe.api.Selection(); | |
if (selection.selection.isCollapsed) { | |
scribe.transactionManager.run(function () { | |
var aNode = selection.getContaining(function (node) { | |
return node.nodeName === 'A'; | |
}); | |
if (aNode) { | |
selection.placeMarkers(); | |
element.unwrap(aNode.parentNode, aNode); | |
selection.selectMarkers(); | |
} | |
}); | |
} else { | |
scribe.api.Command.prototype.execute.apply(this, arguments); | |
} | |
}; | |
unlinkCommand.queryEnabled = function () { | |
var selection = new scribe.api.Selection(); | |
if (selection.selection.isCollapsed) { | |
return !!selection.getContaining(function (node) { | |
return node.nodeName === 'A'; | |
}); | |
} else { | |
return scribe.api.Command.prototype.queryEnabled.apply(this, arguments); | |
} | |
}; | |
scribe.commands.unlink = unlinkCommand; | |
}; | |
}; | |
},{"scribe-common/src/element":23}]},{},[24])(24) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment