Skip to content

Commit

Permalink
Safari Tests Passing
Browse files Browse the repository at this point in the history
  • Loading branch information
ksorv committed Jul 27, 2020
1 parent ba35736 commit c40c286
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 160 deletions.
116 changes: 0 additions & 116 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,51 +36,6 @@ module.exports = function (grunt) {
'src/js/defaults/options.js',
'src/js/version.js'
];
// browsers = [{
// browserName: 'internet explorer',
// version: '9',
// platform: 'WIN7'
// }, {
// browserName: 'internet explorer',
// version: '10',
// platform: 'WIN8'
// }, {
// browserName: 'internet explorer',
// version: '11',
// platform: 'WIN8.1'
// }, {
// browserName: 'internet explorer',
// version: '11',
// platform: 'Windows 10'
// }, {
// browserName: 'MicrosoftEdge',
// platform: 'Windows 10'
// }, {
// browserName: 'chrome',
// platform: 'WIN8.1'
// }, {
// browserName: 'chrome',
// platform: 'Windows 10'
// }, {
// browserName: 'googlechrome',
// platform: 'OS X 10.11'
// }, {
// browserName: 'firefox',
// platform: 'WIN8.1'
// }, {
// browserName: 'firefox',
// platform: 'Windows 10'
// }, {
// browserName: 'firefox',
// platform: 'OS X 10.11'
// }, {
// browserName: 'safari',
// platform: 'OS X 10.10'
// }, {
// browserName: 'safari',
// platform: 'OS X 10.11'
// }];

gruntConfig.connect = {
server: {
options: {
Expand Down Expand Up @@ -119,49 +74,6 @@ module.exports = function (grunt) {
}
};

// gruntConfig.jasmine = {
// suite: {
// src: [srcFiles],
// options: {
// specs: ['spec/*.spec.js'],
// helpers: 'spec/helpers/*.js',
// vendor: [
// 'node_modules/lodash/index.js',
// 'spec/vendor/jasmine-jsreporter.js',
// 'spec/vendor/jasmine-jsreporter-script.js'
// ],
// polyfills: [
// 'src/js/polyfills.js'
// ],
// styles: 'dist/css/*.css',
// junit: {
// path: 'reports/jasmine/',
// consolidate: true
// },
// keepRunner: true,
// template: require('grunt-template-jasmine-istanbul'),
// templateOptions: {
// coverage: 'reports/jasmine/coverage.json',
// report: [{
// type: 'lcov',
// options: {
// dir: 'reports/jasmine/lcov'
// }
// }],
// files: srcFiles.concat('!src/js/extensions/deprecated/*')
// },
// summary: true
// }
// },
// spec: {
// src: 'src/js/**/*.js',
// options: {
// specs: ['spec/<%= globalConfig.file %>.spec.js'],
// helpers: 'spec/helpers/*.js'
// }
// }
// };

gruntConfig.karma = {
unit: {
configFile: 'karma.conf.js'
Expand Down Expand Up @@ -308,31 +220,6 @@ module.exports = function (grunt) {
}
};

// gruntConfig['saucelabs-jasmine'] = {
// all: {
// options: {
// urls: ['http://localhost:9999/_SpecRunner.html'],
// tunnelTimeout: 5,
// build: process.env.TRAVIS_JOB_ID,
// concurrency: 3,
// browsers: browsers,
// sauceConfig: {
// public: 'public',
// build: process.env.TRAVIS_JOB_ID,
// name: 'medium-editor-tests',
// maxDuration: 900,
// idleTimeout: 600
// }
// }
// }
// };

// gruntConfig.coveralls = {
// dist: {
// src: 'reports/jasmine/lcov/lcov.info'
// }
// };

gruntConfig.bump = {
options: {
files: ['package.json', 'src/js/version.js'],
Expand All @@ -356,12 +243,10 @@ module.exports = function (grunt) {
if (parseInt(process.env.TRAVIS_PULL_REQUEST, 10) > 0) {
grunt.registerTask('travis', ['jshint', 'jscs', 'karma:unit', 'csslint']);
} else {
// grunt.registerTask('travis', ['connect', 'jshint', 'jscs', 'jasmine:suite', 'csslint', 'saucelabs-jasmine', 'coveralls']);
grunt.registerTask('travis', ['jshint', 'jscs', 'csslint', 'karma:unit']);
}

grunt.registerTask('test', ['jshint', 'jscs', 'concat', 'csslint', 'karma:dev']);
// grunt.registerTask('sauce', ['connect', 'saucelabs-jasmine']);
grunt.registerTask('js', ['jshint', 'jscs', 'concat', 'karma:dev', 'uglify']);
grunt.registerTask('css', ['sass', 'autoprefixer', 'cssmin', 'csslint']);
grunt.registerTask('default', ['js', 'css']);
Expand All @@ -371,7 +256,6 @@ module.exports = function (grunt) {
grunt.task.run(taskName + ':spec');
});

// release tasks
grunt.registerTask('patch', ['bump', 'css', 'js']);
grunt.registerTask('minor', ['bump:minor', 'css', 'js']);
grunt.registerTask('major', ['bump:major', 'css', 'js']);
Expand Down
10 changes: 4 additions & 6 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global module, process */
/* global module */

module.exports = function (config) {
config.set({
Expand Down Expand Up @@ -75,9 +75,8 @@ module.exports = function (config) {
frameworks: ['jasmine'],

files: [
'dist/css/*.css',
'node_modules/lodash/index.js',
'spec/vendor/jasmine-jsreporter.js',
'spec/vendor/jasmine-jsreporter-script.js',
'src/js/polyfills.js',
'src/js/globals.js',
'src/js/util.js',
Expand Down Expand Up @@ -133,13 +132,12 @@ module.exports = function (config) {

port: 9876,

logLevel: config.LOG_DEBUG,
logLevel: config.LOG_INFO,
colors: true,

autoWatch: false,

// TODO: 'OSXYosemiteSafari', 'OSXElCapitanSafari'
browsers: ['WIN10Edge', 'WIN10Chrome', 'WIN10Firefox', 'WIN81Edge', 'WIN81Chrome', 'WIN81Firefox', 'OSXElCapitanChrome', 'OSXElCapitanFirefox'],
browsers: ['WIN10Edge', 'WIN10Chrome', 'WIN10Firefox', 'WIN81Edge', 'WIN81Chrome', 'WIN81Firefox', 'OSXElCapitanChrome', 'OSXElCapitanFirefox', 'OSXElCapitanSafari', 'OSXYosemiteSafari'],

client: {
clearContext: false
Expand Down
80 changes: 42 additions & 38 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// if current text selection is empty OR previous sibling text is empty OR it is not a list
if ((node && node.textContent.trim() === '' && node.nodeName.toLowerCase() !== 'li') ||
(node.previousElementSibling && node.previousElementSibling.nodeName.toLowerCase() !== 'br' &&
node.previousElementSibling.textContent.trim() === '')) {
node.previousElementSibling.textContent.trim() === '')) {
event.preventDefault();
}
}
Expand Down Expand Up @@ -60,12 +60,12 @@
isHeader = /h\d/i;

if (MediumEditor.util.isKey(event, [MediumEditor.util.keyCode.BACKSPACE, MediumEditor.util.keyCode.ENTER]) &&
// has a preceeding sibling
node.previousElementSibling &&
// in a header
isHeader.test(tagName) &&
// at the very end of the block
MediumEditor.selection.getCaretOffsets(node).left === 0) {
// has a preceeding sibling
node.previousElementSibling &&
// in a header
isHeader.test(tagName) &&
// at the very end of the block
MediumEditor.selection.getCaretOffsets(node).left === 0) {
if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.BACKSPACE) && isEmpty.test(node.previousElementSibling.innerHTML)) {
// backspacing the begining of a header into an empty previous element will
// change the tagName of the current node to prevent one
Expand All @@ -81,15 +81,15 @@
event.preventDefault();
}
} else if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.DELETE) &&
// between two sibling elements
node.nextElementSibling &&
node.previousElementSibling &&
// not in a header
!isHeader.test(tagName) &&
// in an empty tag
isEmpty.test(node.innerHTML) &&
// when the next tag *is* a header
isHeader.test(node.nextElementSibling.nodeName.toLowerCase())) {
// between two sibling elements
node.nextElementSibling &&
node.previousElementSibling &&
// not in a header
!isHeader.test(tagName) &&
// in an empty tag
isEmpty.test(node.innerHTML) &&
// when the next tag *is* a header
isHeader.test(node.nextElementSibling.nodeName.toLowerCase())) {
// hitting delete in an empty element preceding a header, ex:
// <p>[CURSOR]</p><h1>Header</h1>
// Will cause the h1 to become a paragraph.
Expand All @@ -102,16 +102,16 @@

event.preventDefault();
} else if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.BACKSPACE) &&
tagName === 'li' &&
// hitting backspace inside an empty li
isEmpty.test(node.innerHTML) &&
// is first element (no preceeding siblings)
!node.previousElementSibling &&
// parent also does not have a sibling
!node.parentElement.previousElementSibling &&
// is not the only li in a list
node.nextElementSibling &&
node.nextElementSibling.nodeName.toLowerCase() === 'li') {
tagName === 'li' &&
// hitting backspace inside an empty li
isEmpty.test(node.innerHTML) &&
// is first element (no preceeding siblings)
!node.previousElementSibling &&
// parent also does not have a sibling
!node.parentElement.previousElementSibling &&
// is not the only li in a list
node.nextElementSibling &&
node.nextElementSibling.nodeName.toLowerCase() === 'li') {
// backspacing in an empty first list element in the first list (with more elements) ex:
// <ul><li>[CURSOR]</li><li>List Item 2</li></ul>
// will remove the first <li> but add some extra element before (varies based on browser)
Expand All @@ -133,16 +133,16 @@

event.preventDefault();
} else if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.BACKSPACE) &&
(MediumEditor.util.getClosestTag(node, 'blockquote') !== false) &&
MediumEditor.selection.getCaretOffsets(node).left === 0) {
(MediumEditor.util.getClosestTag(node, 'blockquote') !== false) &&
MediumEditor.selection.getCaretOffsets(node).left === 0) {

// when cursor is at the begining of the element and the element is <blockquote>
// then pressing backspace key should change the <blockquote> to a <p> tag
event.preventDefault();
MediumEditor.util.execFormatBlock(this.options.ownerDocument, 'p');
} else if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.ENTER) &&
(MediumEditor.util.getClosestTag(node, 'blockquote') !== false) &&
MediumEditor.selection.getCaretOffsets(node).right === 0) {
(MediumEditor.util.getClosestTag(node, 'blockquote') !== false) &&
MediumEditor.selection.getCaretOffsets(node).right === 0) {

// when cursor is at the end of <blockquote>,
// then pressing enter key should create <p> tag, not <blockquote>
Expand All @@ -155,10 +155,10 @@

event.preventDefault();
} else if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.BACKSPACE) &&
MediumEditor.util.isMediumEditorElement(node.parentElement) &&
!node.previousElementSibling &&
node.nextElementSibling &&
isEmpty.test(node.innerHTML)) {
MediumEditor.util.isMediumEditorElement(node.parentElement) &&
!node.previousElementSibling &&
node.nextElementSibling &&
isEmpty.test(node.innerHTML)) {

// when cursor is in the first element, it's empty and user presses backspace,
// do delete action instead to get rid of the first element and move caret to 2nd
Expand Down Expand Up @@ -334,8 +334,8 @@
// If any of the elements don't have the toolbar disabled
// We need a toolbar
if (this.elements.every(function (element) {
return !!element.getAttribute('data-disable-toolbar');
})) {
return !!element.getAttribute('data-disable-toolbar');
})) {
return false;
}

Expand Down Expand Up @@ -968,7 +968,11 @@

getSelectedParentElement: function (range) {
if (range === undefined) {
range = this.options.contentWindow.getSelection().getRangeAt(0);
try {
range = this.options.contentWindow.getSelection().getRangeAt(0);
} catch (err) {
return {};
}
}
return MediumEditor.selection.getSelectedParentElement(range);
},
Expand Down Expand Up @@ -1123,7 +1127,7 @@
0,
parentElement.lastChild,
parentElement.lastChild.nodeType === 3 ?
parentElement.lastChild.nodeValue.length : parentElement.lastChild.childNodes.length
parentElement.lastChild.nodeValue.length : parentElement.lastChild.childNodes.length
);
} else {
MediumEditor.selection.select(
Expand Down

0 comments on commit c40c286

Please sign in to comment.