Comparing version 1.3.0 to 1.4.0
@@ -7,151 +7,155 @@ /** | ||
var isEscKeyEnabled = function() { | ||
return !window.rkdModal || window.rkdModal.escKey; | ||
return !window.rkdModal || window.rkdModal.escKey; | ||
}; | ||
$(function() { | ||
var openModal = function($modal) { | ||
$(document).trigger('rkd-modal:before:open', $modal); | ||
var openModal = function($modal) { | ||
$(document).trigger('rkd-modal:before:open', $modal); | ||
$modal.addClass('modal-open'); | ||
$modal.find('input.modal-state').prop('checked', true).trigger('change'); | ||
$modal.addClass('modal-open'); | ||
$modal.find('input.modal-state').prop('checked', true).trigger('change'); | ||
if (isEscKeyEnabled()) { | ||
$(document).on('keyup.'+ESC_KEY_NAMESPACE, function(e) { | ||
if (e.keyCode === ESC_KEY) { | ||
closeModal($modal); | ||
if (isEscKeyEnabled()) { | ||
$(document).on('keyup.'+ESC_KEY_NAMESPACE, function(e) { | ||
if (e.keyCode === ESC_KEY) { | ||
closeModal($modal); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
$(document).trigger('rkd-modal:after:open', $modal); | ||
}; | ||
$(document).trigger('rkd-modal:after:open', $modal); | ||
}; | ||
var closeModal = function($modal) { | ||
$(document).trigger('rkd-modal:before:close', $modal); | ||
var closeModal = function($modal) { | ||
$(document).trigger('rkd-modal:before:close', $modal); | ||
$modal.removeClass('modal-open'); | ||
$modal.find('input.modal-state').prop('checked', false).trigger('change'); | ||
$modal.removeClass('modal-open'); | ||
$modal.find('input.modal-state').prop('checked', false).trigger('change'); | ||
// Remove ESC key listener | ||
if (isEscKeyEnabled()) { | ||
$(document).unbind('keyup.'+ESC_KEY_NAMESPACE); | ||
} | ||
// Remove ESC key listener | ||
if (isEscKeyEnabled()) { | ||
$(document).unbind('keyup.'+ESC_KEY_NAMESPACE); | ||
} | ||
$(document).trigger('rkd-modal:after:close', $modal); | ||
}; | ||
$(document).trigger('rkd-modal:after:close', $modal); | ||
}; | ||
// Close modal on close button and clicking outside of modal | ||
$(document).on("click", ".modal-fade-screen, .modal-close", function() { | ||
var $modal = $(this).closest('.modal'); | ||
closeModal($modal); | ||
}); | ||
// Close modal on close button and clicking outside of modal | ||
$(document).on("click", ".modal-fade-screen, .modal-close", function() { | ||
var $modal = $(this).closest('.modal'); | ||
closeModal($modal); | ||
}); | ||
$(document).on("click", ".modal-inner", function(e) { | ||
e.stopPropagation(); | ||
}); | ||
$(document).on("click", ".modal-inner", function(e) { | ||
e.stopPropagation(); | ||
}); | ||
// Simple content modal | ||
$(document).on("click", ".rkd-modal", function(e) { | ||
e.preventDefault(); | ||
var $modal = $('#'+$(this).data('rkd-modal-id')); | ||
openModal($modal); | ||
}); | ||
// Simple content modal | ||
$(document).on("click", ".rkd-modal", function(e) { | ||
e.preventDefault(); | ||
var $modal = $('#'+$(this).data('rkd-modal-id')); | ||
openModal($modal); | ||
}); | ||
// Modal ajax link | ||
$(document).on("click", ".rkd-modal-ajax, .rkd-modal-this", function(e) { | ||
e.preventDefault(); | ||
var $modal; | ||
var id = $(this).data('rkd-modal-id'); | ||
// Modal ajax link | ||
$(document).on("click", ".rkd-modal-ajax, .rkd-modal-this", function(e) { | ||
e.preventDefault(); | ||
var $modal; | ||
var id = $(this).data('rkd-modal-id'); | ||
// Modal exists? | ||
if(id){ | ||
$modal = $('#'+id); | ||
}else{ | ||
// Create new modal | ||
$modal = createAjaxModal(); | ||
// Modal exists? | ||
if (id) { | ||
$modal = $('#'+id); | ||
} else { | ||
// Create new modal | ||
$modal = createAjaxModal(); | ||
// Set id so we can have "cache" | ||
$(this).data('rkd-modal-id', $modal.attr('id')); | ||
} | ||
// Set id so we can have "cache" | ||
$(this).data('rkd-modal-id', $modal.attr('id')); | ||
} | ||
var $loading = $modal.find('.loading'); | ||
var $loading = $modal.find('.loading'); | ||
// Open modal | ||
openModal($modal); | ||
// Open modal | ||
openModal($modal); | ||
// Take content inside of this element | ||
if ($(this).hasClass('rkd-modal-this')){ | ||
// Set loaded content to our modal | ||
$modal.find('.modal-content').html($(this).html()); | ||
// Hide loader | ||
$loading.hide(); | ||
return; | ||
} | ||
// Take content inside of this element | ||
if ($(this).hasClass('rkd-modal-this')) { | ||
// Set loaded content to our modal | ||
$modal.find('.modal-content').html($(this).html()); | ||
// Check if content is already loaded? | ||
if($modal.hasClass('content-loaded')){ | ||
return; | ||
} | ||
$(document).trigger('rkd-modal:content:loaded', $modal); | ||
var selector = $(this).data('rkd-modal-selector'); | ||
// Hide loader | ||
$loading.hide(); | ||
return; | ||
} | ||
// Show loader | ||
$loading.show(); | ||
// Check if content is already loaded? | ||
if ($modal.hasClass('content-loaded')) { | ||
return; | ||
} | ||
// Make ajax call to current link url | ||
$.ajax($(this).attr('href')) | ||
.done(function(data){ | ||
// If has selector, get wanted content | ||
if(selector){ | ||
data = $(data).find(selector); | ||
} | ||
else if($(data).find('.rkd-modal-content')){ | ||
data = $(data).find('.rkd-modal-content'); | ||
} | ||
var selector = $(this).data('rkd-modal-selector'); | ||
// Set loaded content to our modal | ||
$modal.find('.modal-content').html(data); | ||
// Show loader | ||
$loading.show(); | ||
// Add class to specify that content has already been loaded | ||
$modal.addClass('content-loaded'); | ||
}) | ||
.fail(function(){ | ||
// Request failed | ||
$modal.find('.modal-content').html('Something went wrong. Please try again later.'); | ||
}) | ||
.always(function(){ | ||
// Hide loader | ||
$loading.hide(); | ||
// Make ajax call to current link url | ||
$.ajax($(this).attr('href')) | ||
.done(function(data) { | ||
// If has selector, get wanted content | ||
if (selector) { | ||
data = $(data).find(selector); | ||
} else if($(data).find('.rkd-modal-content')) { | ||
data = $(data).find('.rkd-modal-content'); | ||
} | ||
// Set loaded content to our modal | ||
$modal.find('.modal-content').html(data); | ||
$(document).trigger('rkd-modal:content:loaded', $modal); | ||
// Add class to specify that content has already been loaded | ||
$modal.addClass('content-loaded'); | ||
}) | ||
.fail(function() { | ||
// Request failed | ||
$modal.find('.modal-content').html('Something went wrong. Please try again later.'); | ||
}) | ||
.always(function() { | ||
// Hide loader | ||
$loading.hide(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
/* Create ajax modal if there is no modal for current link */ | ||
var createAjaxModal = function(){ | ||
// Create unique ID | ||
var ID = '_' + Math.random().toString(36).substr(2, 9); | ||
var createAjaxModal = function() { | ||
// Create unique ID | ||
var ID = '_' + Math.random().toString(36).substr(2, 9); | ||
var modalHTML = '<div class="modal" id="'+ID+'">' + | ||
'<input class="modal-state" type="checkbox" />' + | ||
'<div class="modal-fade-screen">' + | ||
var modalHTML = '<div class="modal rkd-modal" id="'+ID+'">' + | ||
'<input class="modal-state" type="checkbox" />' + | ||
'<div class="modal-fade-screen">' + | ||
'<div class="modal-inner">' + | ||
'<!-- Close button-->' + | ||
'<div class="modal-close"></div>' + | ||
'<!-- Loader -->' + | ||
'<div class="sk-three-bounce loading">' + | ||
'<!-- Close button-->' + | ||
'<div class="modal-close"></div>' + | ||
'<!-- Loader -->' + | ||
'<div class="sk-three-bounce loading">' + | ||
'<div class="sk-child sk-bounce1"></div>' + | ||
'<div class="sk-child sk-bounce2"></div>' + | ||
'<div class="sk-child sk-bounce3"></div>' + | ||
'</div>' + | ||
'</div>' + | ||
'<!-- Content will be loaded in here with AJAX -->' + | ||
'<div class="modal-content"></div>' + | ||
'<!-- Content will be loaded in here with AJAX -->' + | ||
'<div class="modal-content"></div>' + | ||
'</div>' + | ||
'</div>' + | ||
'</div>' + | ||
'</div>'; | ||
// Add to document | ||
$('body').append(modalHTML); | ||
// Add to document | ||
$('body').append(modalHTML); | ||
return $('#'+ID); | ||
return $('#'+ID); | ||
}; |
@@ -1,1 +0,2 @@ | ||
var ESC_KEY=27,ESC_KEY_NAMESPACE="rkd-modal-escape",isEscKeyEnabled=function(){return!window.rkdModal||window.rkdModal.escKey};$(function(){var a=function(a){$(document).trigger("rkd-modal:before:open",a),a.addClass("modal-open"),a.find("input.modal-state").prop("checked",!0).trigger("change"),isEscKeyEnabled()&&$(document).on("keyup."+ESC_KEY_NAMESPACE,function(c){c.keyCode===ESC_KEY&&b(a)}),$(document).trigger("rkd-modal:after:open",a)},b=function(a){$(document).trigger("rkd-modal:before:close",a),a.removeClass("modal-open"),a.find("input.modal-state").prop("checked",!1).trigger("change"),isEscKeyEnabled()&&$(document).unbind("keyup."+ESC_KEY_NAMESPACE),$(document).trigger("rkd-modal:after:close",a)};$(document).on("click",".modal-fade-screen, .modal-close",function(){var a=$(this).closest(".modal");b(a)}),$(document).on("click",".modal-inner",function(a){a.stopPropagation()}),$(document).on("click",".rkd-modal",function(b){b.preventDefault();var c=$("#"+$(this).data("rkd-modal-id"));a(c)}),$(document).on("click",".rkd-modal-ajax, .rkd-modal-this",function(b){b.preventDefault();var c,d=$(this).data("rkd-modal-id");d?c=$("#"+d):(c=createAjaxModal(),$(this).data("rkd-modal-id",c.attr("id")));var e=c.find(".loading");if(a(c),$(this).hasClass("rkd-modal-this"))return c.find(".modal-content").html($(this).html()),void e.hide();if(!c.hasClass("content-loaded")){var f=$(this).data("rkd-modal-selector");e.show(),$.ajax($(this).attr("href")).done(function(a){f?a=$(a).find(f):$(a).find(".rkd-modal-content")&&(a=$(a).find(".rkd-modal-content")),c.find(".modal-content").html(a),c.addClass("content-loaded")}).fail(function(){c.find(".modal-content").html("Something went wrong. Please try again later.")}).always(function(){e.hide()})}})});var createAjaxModal=function(){var a="_"+Math.random().toString(36).substr(2,9),b='<div class="modal" id="'+a+'"><input class="modal-state" type="checkbox" /><div class="modal-fade-screen"><div class="modal-inner"><!-- Close button--><div class="modal-close"></div><!-- Loader --><div class="sk-three-bounce loading"><div class="sk-child sk-bounce1"></div><div class="sk-child sk-bounce2"></div><div class="sk-child sk-bounce3"></div></div><!-- Content will be loaded in here with AJAX --><div class="modal-content"></div></div></div></div>';return $("body").append(b),$("#"+a)}; | ||
var ESC_KEY=27,ESC_KEY_NAMESPACE="rkd-modal-escape",isEscKeyEnabled=function(){return!window.rkdModal||window.rkdModal.escKey};$(function(){var a=function(a){$(document).trigger("rkd-modal:before:open",a),a.addClass("modal-open"),a.find("input.modal-state").prop("checked",!0).trigger("change"),isEscKeyEnabled()&&$(document).on("keyup."+ESC_KEY_NAMESPACE,function(c){c.keyCode===ESC_KEY&&b(a)}),$(document).trigger("rkd-modal:after:open",a)},b=function(a){$(document).trigger("rkd-modal:before:close",a),a.removeClass("modal-open"),a.find("input.modal-state").prop("checked",!1).trigger("change"),isEscKeyEnabled()&&$(document).unbind("keyup."+ESC_KEY_NAMESPACE),$(document).trigger("rkd-modal:after:close",a)};$(document).on("click",".modal-fade-screen, .modal-close",function(){var a=$(this).closest(".modal");b(a)}),$(document).on("click",".modal-inner",function(a){a.stopPropagation()}),$(document).on("click",".rkd-modal",function(b){b.preventDefault();var c=$("#"+$(this).data("rkd-modal-id"));a(c)}),$(document).on("click",".rkd-modal-ajax, .rkd-modal-this",function(b){b.preventDefault();var c,d=$(this).data("rkd-modal-id");d?c=$("#"+d):(c=createAjaxModal(),$(this).data("rkd-modal-id",c.attr("id")));var e=c.find(".loading");if(a(c),$(this).hasClass("rkd-modal-this"))return c.find(".modal-content").html($(this).html()),$(document).trigger("rkd-modal:content:loaded",c),void e.hide();if(!c.hasClass("content-loaded")){var f=$(this).data("rkd-modal-selector");e.show(),$.ajax($(this).attr("href")).done(function(a){f?a=$(a).find(f):$(a).find(".rkd-modal-content")&&(a=$(a).find(".rkd-modal-content")),c.find(".modal-content").html(a),$(document).trigger("rkd-modal:content:loaded",c),c.addClass("content-loaded")}).fail(function(){c.find(".modal-content").html("Something went wrong. Please try again later.")}).always(function(){e.hide()})}})});var createAjaxModal=function(){var a="_"+Math.random().toString(36).substr(2,9),b='<div class="modal rkd-modal" id="'+a+'"><input class="modal-state" type="checkbox" /><div class="modal-fade-screen"><div class="modal-inner"><!-- Close button--><div class="modal-close"></div><!-- Loader --><div class="sk-three-bounce loading"><div class="sk-child sk-bounce1"></div><div class="sk-child sk-bounce2"></div><div class="sk-child sk-bounce3"></div></div><!-- Content will be loaded in here with AJAX --><div class="modal-content"></div></div></div></div>';return $("body").append(b),$("#"+a)}; | ||
//# sourceMappingURL=rkd-modal.min.js.map |
187
Gruntfile.js
module.exports = function(grunt) { | ||
'use strict'; | ||
'use strict'; | ||
// Load all grunt tasks | ||
require('load-grunt-tasks')(grunt); | ||
// Load all grunt tasks | ||
require('load-grunt-tasks')(grunt); | ||
// Init config | ||
grunt.initConfig({ | ||
// Removes old files. | ||
clean: ['dist'], | ||
// Init config | ||
grunt.initConfig({ | ||
// Removes old files. | ||
clean: ['dist'], | ||
// Copys the files from the src folder to the dist folder. | ||
copy: { | ||
js: { | ||
files: [ | ||
{ | ||
expand: true, | ||
cwd: 'src', | ||
src: '**.js', | ||
dest: 'dist/' | ||
} | ||
] | ||
}, | ||
}, | ||
// Copys the files from the src folder to the dist folder. | ||
copy: { | ||
js: { | ||
files: [{ | ||
expand: true, | ||
cwd: 'src', | ||
src: '**.js', | ||
dest: 'dist/' | ||
}] | ||
}, | ||
}, | ||
// Minifies the javascript files. | ||
uglify: { | ||
build: { | ||
files: [{ | ||
expand: true, | ||
cwd: 'dist/', | ||
src: [ | ||
'*.js', | ||
'!*.min.js' | ||
], | ||
dest: 'dist/', | ||
ext: '.min.js' | ||
}] | ||
} | ||
}, | ||
// Minifies the javascript files. | ||
uglify: { | ||
build: { | ||
options: { | ||
sourceMap: true | ||
}, | ||
files: [{ | ||
expand: true, | ||
cwd: 'dist/', | ||
src: [ | ||
'*.js', | ||
'!*.min.js' | ||
], | ||
dest: 'dist/', | ||
ext: '.min.js' | ||
}] | ||
} | ||
}, | ||
// Compiles the stylesheet files. | ||
sass: { | ||
build: { | ||
options: { | ||
includePaths: [ | ||
'node_modules/' | ||
], | ||
style: 'expanded', | ||
sourcemap: 'none' | ||
// Compiles the stylesheet files. | ||
sass: { | ||
build: { | ||
options: { | ||
includePaths: [ | ||
'node_modules/' | ||
], | ||
style: 'expanded', | ||
sourcemap: 'none' | ||
}, | ||
files: [{ | ||
expand: true, | ||
cwd: 'src/', | ||
src: 'rkd-modal.scss', | ||
dest: 'dist/', | ||
ext: '.css' | ||
}] | ||
} | ||
}, | ||
files: [{ | ||
expand: true, | ||
cwd: 'src/', | ||
src: 'rkd-modal.scss', | ||
dest: 'dist/', | ||
ext: '.css' | ||
}] | ||
} | ||
}, | ||
// Minifies the stylesheet files. | ||
cssmin: { | ||
build: { | ||
expand: true, | ||
cwd: 'dist/', | ||
src: [ | ||
'*.css', | ||
'!*.min.css' | ||
], | ||
dest: 'dist/', | ||
ext: '.min.css' | ||
} | ||
}, | ||
// Minifies the stylesheet files. | ||
cssmin: { | ||
build: { | ||
expand: true, | ||
cwd: 'dist/', | ||
src: [ | ||
'*.css', | ||
'!*.min.css' | ||
], | ||
dest: 'dist/', | ||
ext: '.min.css' | ||
} | ||
}, | ||
// Lints JS files for errors | ||
jshint: { | ||
build: { | ||
files: { | ||
src: ['src/**/*.js'] | ||
} | ||
} | ||
}, | ||
// Lints JS files for errors | ||
jshint: { | ||
build: { | ||
files: { | ||
src: ['src/**/*.js'] | ||
} | ||
} | ||
}, | ||
// Lints SASS files for errors | ||
sasslint: { | ||
build: ['src/**/*.scss'], | ||
}, | ||
// Lints SASS files for errors | ||
sasslint: { | ||
build: ['src/**/*.scss'], | ||
}, | ||
// Watches the project for changes and recompiles the output files. | ||
watch: { | ||
// Watches the project for changes and recompiles the output files. | ||
watch: { | ||
javascript: { | ||
files: 'src/**/*.js', | ||
tasks: ['jshint:build', 'copy:js', 'uglify:build'] | ||
}, | ||
javascript: { | ||
files: 'src/**/*.js', | ||
tasks: ['jshint:build', 'copy:js', 'uglify:build'] | ||
}, | ||
sass: { | ||
files: 'src/**/*.scss', | ||
tasks: ['sasslint:build', 'sass:build', 'cssmin:build'] | ||
}, | ||
} | ||
}); | ||
sass: { | ||
files: 'src/**/*.scss', | ||
tasks: ['sasslint:build', 'sass:build', 'cssmin:build'] | ||
}, | ||
} | ||
}); | ||
// Default taks | ||
grunt.registerTask('default', ['clean', 'copy', 'uglify', 'sasslint', 'sass', 'cssmin']); | ||
// Default taks | ||
grunt.registerTask('default', ['clean', 'copy', 'uglify', 'sasslint', 'sass', 'cssmin']); | ||
}; |
{ | ||
"name": "rkd-modal", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Plain content and AJAX supported modal.", | ||
@@ -29,2 +29,3 @@ "main": "Gruntfile.js", | ||
"bourbon": "^4.3.4", | ||
"bourbon-neat": "^1.9.1", | ||
"grunt": "^1.0.3", | ||
@@ -34,3 +35,3 @@ "grunt-contrib-clean": "^1.0.0", | ||
"grunt-contrib-cssmin": "^1.0.1", | ||
"grunt-contrib-jshint": "^1.0.0", | ||
"grunt-contrib-jshint": "^1.1.0", | ||
"grunt-contrib-sass": "^1.0.0", | ||
@@ -43,8 +44,7 @@ "grunt-contrib-uglify": "^1.0.1", | ||
"load-grunt-tasks": "^3.5.0", | ||
"merge": ">=1.2.1", | ||
"sass-lint": "^1.12.1", | ||
"spinkit": "^1.2.5", | ||
"bourbon-neat": "^1.9.1", | ||
"merge": ">=1.2.1" | ||
"spinkit": "^1.2.5" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -0,2 +1,4 @@ | ||
[![npm version](https://badge.fury.io/js/rkd-modal.svg)](https://badge.fury.io/js/rkd-modal) | ||
[![npm](https://img.shields.io/npm/dt/rkd-modal.svg)](https://www.npmjs.com/package/rkd-modal) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/renekorss/rkd-modal/badge.svg?targetFile=package.json)](https://snyk.io/test/github/renekorss/rkd-modal?targetFile=package.json) | ||
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) | ||
@@ -21,5 +23,5 @@ | ||
<a | ||
href="https://cors.io/?http://example.com/" | ||
class="rkd-modal-ajax" | ||
data-rkd-modal-selector="p" | ||
href="https://cors.io/?http://example.com/" | ||
class="rkd-modal-ajax" | ||
data-rkd-modal-selector="p" | ||
>Open ajax modal</a> | ||
@@ -55,11 +57,11 @@ ```` | ||
<div class="modal" id="modal-content"> | ||
<input class="modal-state" type="checkbox" /> | ||
<div class="modal-fade-screen"> | ||
<div class="modal-inner"> | ||
<div class="modal-close"></div> | ||
<h1>Modal Title</h1> | ||
<p class="modal-intro">Intro text</p> | ||
<p class="modal-content">Body text</p> | ||
<input class="modal-state" type="checkbox" /> | ||
<div class="modal-fade-screen"> | ||
<div class="modal-inner"> | ||
<div class="modal-close"></div> | ||
<h1>Modal Title</h1> | ||
<p class="modal-intro">Intro text</p> | ||
<p class="modal-content">Body text</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
@@ -82,2 +84,3 @@ ```` | ||
- `rkd-modal:after:close` | ||
- `rkd-modal:content:loaded` | ||
@@ -88,4 +91,4 @@ Events are fired on `$(document)` object, so listen like this: | ||
$(document).on('rkd-modal:before:open', function(e, $modal) { | ||
// Do whatever you need | ||
// $modal is jQuery object representing current modal | ||
// Do whatever you need | ||
// $modal is jQuery object representing current modal | ||
}); | ||
@@ -100,3 +103,3 @@ ```` | ||
window.rkdModal = { | ||
escKey: false | ||
escKey: false | ||
}; | ||
@@ -113,2 +116,2 @@ ```` | ||
[MIT](LICENSE) | ||
[MIT](LICENSE) |
@@ -7,151 +7,155 @@ /** | ||
var isEscKeyEnabled = function() { | ||
return !window.rkdModal || window.rkdModal.escKey; | ||
return !window.rkdModal || window.rkdModal.escKey; | ||
}; | ||
$(function() { | ||
var openModal = function($modal) { | ||
$(document).trigger('rkd-modal:before:open', $modal); | ||
var openModal = function($modal) { | ||
$(document).trigger('rkd-modal:before:open', $modal); | ||
$modal.addClass('modal-open'); | ||
$modal.find('input.modal-state').prop('checked', true).trigger('change'); | ||
$modal.addClass('modal-open'); | ||
$modal.find('input.modal-state').prop('checked', true).trigger('change'); | ||
if (isEscKeyEnabled()) { | ||
$(document).on('keyup.'+ESC_KEY_NAMESPACE, function(e) { | ||
if (e.keyCode === ESC_KEY) { | ||
closeModal($modal); | ||
if (isEscKeyEnabled()) { | ||
$(document).on('keyup.'+ESC_KEY_NAMESPACE, function(e) { | ||
if (e.keyCode === ESC_KEY) { | ||
closeModal($modal); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
$(document).trigger('rkd-modal:after:open', $modal); | ||
}; | ||
$(document).trigger('rkd-modal:after:open', $modal); | ||
}; | ||
var closeModal = function($modal) { | ||
$(document).trigger('rkd-modal:before:close', $modal); | ||
var closeModal = function($modal) { | ||
$(document).trigger('rkd-modal:before:close', $modal); | ||
$modal.removeClass('modal-open'); | ||
$modal.find('input.modal-state').prop('checked', false).trigger('change'); | ||
$modal.removeClass('modal-open'); | ||
$modal.find('input.modal-state').prop('checked', false).trigger('change'); | ||
// Remove ESC key listener | ||
if (isEscKeyEnabled()) { | ||
$(document).unbind('keyup.'+ESC_KEY_NAMESPACE); | ||
} | ||
// Remove ESC key listener | ||
if (isEscKeyEnabled()) { | ||
$(document).unbind('keyup.'+ESC_KEY_NAMESPACE); | ||
} | ||
$(document).trigger('rkd-modal:after:close', $modal); | ||
}; | ||
$(document).trigger('rkd-modal:after:close', $modal); | ||
}; | ||
// Close modal on close button and clicking outside of modal | ||
$(document).on("click", ".modal-fade-screen, .modal-close", function() { | ||
var $modal = $(this).closest('.modal'); | ||
closeModal($modal); | ||
}); | ||
// Close modal on close button and clicking outside of modal | ||
$(document).on("click", ".modal-fade-screen, .modal-close", function() { | ||
var $modal = $(this).closest('.modal'); | ||
closeModal($modal); | ||
}); | ||
$(document).on("click", ".modal-inner", function(e) { | ||
e.stopPropagation(); | ||
}); | ||
$(document).on("click", ".modal-inner", function(e) { | ||
e.stopPropagation(); | ||
}); | ||
// Simple content modal | ||
$(document).on("click", ".rkd-modal", function(e) { | ||
e.preventDefault(); | ||
var $modal = $('#'+$(this).data('rkd-modal-id')); | ||
openModal($modal); | ||
}); | ||
// Simple content modal | ||
$(document).on("click", ".rkd-modal", function(e) { | ||
e.preventDefault(); | ||
var $modal = $('#'+$(this).data('rkd-modal-id')); | ||
openModal($modal); | ||
}); | ||
// Modal ajax link | ||
$(document).on("click", ".rkd-modal-ajax, .rkd-modal-this", function(e) { | ||
e.preventDefault(); | ||
var $modal; | ||
var id = $(this).data('rkd-modal-id'); | ||
// Modal ajax link | ||
$(document).on("click", ".rkd-modal-ajax, .rkd-modal-this", function(e) { | ||
e.preventDefault(); | ||
var $modal; | ||
var id = $(this).data('rkd-modal-id'); | ||
// Modal exists? | ||
if(id){ | ||
$modal = $('#'+id); | ||
}else{ | ||
// Create new modal | ||
$modal = createAjaxModal(); | ||
// Modal exists? | ||
if (id) { | ||
$modal = $('#'+id); | ||
} else { | ||
// Create new modal | ||
$modal = createAjaxModal(); | ||
// Set id so we can have "cache" | ||
$(this).data('rkd-modal-id', $modal.attr('id')); | ||
} | ||
// Set id so we can have "cache" | ||
$(this).data('rkd-modal-id', $modal.attr('id')); | ||
} | ||
var $loading = $modal.find('.loading'); | ||
var $loading = $modal.find('.loading'); | ||
// Open modal | ||
openModal($modal); | ||
// Open modal | ||
openModal($modal); | ||
// Take content inside of this element | ||
if ($(this).hasClass('rkd-modal-this')){ | ||
// Set loaded content to our modal | ||
$modal.find('.modal-content').html($(this).html()); | ||
// Hide loader | ||
$loading.hide(); | ||
return; | ||
} | ||
// Take content inside of this element | ||
if ($(this).hasClass('rkd-modal-this')) { | ||
// Set loaded content to our modal | ||
$modal.find('.modal-content').html($(this).html()); | ||
// Check if content is already loaded? | ||
if($modal.hasClass('content-loaded')){ | ||
return; | ||
} | ||
$(document).trigger('rkd-modal:content:loaded', $modal); | ||
var selector = $(this).data('rkd-modal-selector'); | ||
// Hide loader | ||
$loading.hide(); | ||
return; | ||
} | ||
// Show loader | ||
$loading.show(); | ||
// Check if content is already loaded? | ||
if ($modal.hasClass('content-loaded')) { | ||
return; | ||
} | ||
// Make ajax call to current link url | ||
$.ajax($(this).attr('href')) | ||
.done(function(data){ | ||
// If has selector, get wanted content | ||
if(selector){ | ||
data = $(data).find(selector); | ||
} | ||
else if($(data).find('.rkd-modal-content')){ | ||
data = $(data).find('.rkd-modal-content'); | ||
} | ||
var selector = $(this).data('rkd-modal-selector'); | ||
// Set loaded content to our modal | ||
$modal.find('.modal-content').html(data); | ||
// Show loader | ||
$loading.show(); | ||
// Add class to specify that content has already been loaded | ||
$modal.addClass('content-loaded'); | ||
}) | ||
.fail(function(){ | ||
// Request failed | ||
$modal.find('.modal-content').html('Something went wrong. Please try again later.'); | ||
}) | ||
.always(function(){ | ||
// Hide loader | ||
$loading.hide(); | ||
// Make ajax call to current link url | ||
$.ajax($(this).attr('href')) | ||
.done(function(data) { | ||
// If has selector, get wanted content | ||
if (selector) { | ||
data = $(data).find(selector); | ||
} else if($(data).find('.rkd-modal-content')) { | ||
data = $(data).find('.rkd-modal-content'); | ||
} | ||
// Set loaded content to our modal | ||
$modal.find('.modal-content').html(data); | ||
$(document).trigger('rkd-modal:content:loaded', $modal); | ||
// Add class to specify that content has already been loaded | ||
$modal.addClass('content-loaded'); | ||
}) | ||
.fail(function() { | ||
// Request failed | ||
$modal.find('.modal-content').html('Something went wrong. Please try again later.'); | ||
}) | ||
.always(function() { | ||
// Hide loader | ||
$loading.hide(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
/* Create ajax modal if there is no modal for current link */ | ||
var createAjaxModal = function(){ | ||
// Create unique ID | ||
var ID = '_' + Math.random().toString(36).substr(2, 9); | ||
var createAjaxModal = function() { | ||
// Create unique ID | ||
var ID = '_' + Math.random().toString(36).substr(2, 9); | ||
var modalHTML = '<div class="modal" id="'+ID+'">' + | ||
'<input class="modal-state" type="checkbox" />' + | ||
'<div class="modal-fade-screen">' + | ||
var modalHTML = '<div class="modal rkd-modal" id="'+ID+'">' + | ||
'<input class="modal-state" type="checkbox" />' + | ||
'<div class="modal-fade-screen">' + | ||
'<div class="modal-inner">' + | ||
'<!-- Close button-->' + | ||
'<div class="modal-close"></div>' + | ||
'<!-- Loader -->' + | ||
'<div class="sk-three-bounce loading">' + | ||
'<!-- Close button-->' + | ||
'<div class="modal-close"></div>' + | ||
'<!-- Loader -->' + | ||
'<div class="sk-three-bounce loading">' + | ||
'<div class="sk-child sk-bounce1"></div>' + | ||
'<div class="sk-child sk-bounce2"></div>' + | ||
'<div class="sk-child sk-bounce3"></div>' + | ||
'</div>' + | ||
'</div>' + | ||
'<!-- Content will be loaded in here with AJAX -->' + | ||
'<div class="modal-content"></div>' + | ||
'<!-- Content will be loaded in here with AJAX -->' + | ||
'<div class="modal-content"></div>' + | ||
'</div>' + | ||
'</div>' + | ||
'</div>' + | ||
'</div>'; | ||
// Add to document | ||
$('body').append(modalHTML); | ||
// Add to document | ||
$('body').append(modalHTML); | ||
return $('#'+ID); | ||
return $('#'+ID); | ||
}; |
Sorry, the diff of this file is not supported yet
37604
17
553
112