effective_ckeditor 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29cefd07b38fd6a0458159c1f7d196977ca9b143
4
- data.tar.gz: e03c4f90cefd1259d4f28fa91aa3964036677208
3
+ metadata.gz: d165f84430656b10ab8f8ba62df645964858890a
4
+ data.tar.gz: 708735a82d9871476dccb38f56e0aa7af3d5153a
5
5
  SHA512:
6
- metadata.gz: 968f46e67146402994a093b3f86207ea0b583088b2e8c4b07956c9f518d335507ff06d17207d9a09eb9d5ceb8e4a7ebf4f6f657270055122f1f15a5df9d56063
7
- data.tar.gz: ac7292ed43b694eec95a7eb8645e223c26d15464109d559da239c4ea022634d8fe0b6d191d609db4265fa056fa6c1ce9ecbdc1eec93ed09b355c71ccdefe9b90
6
+ metadata.gz: 1d7636a51adb87a78ab1afe07d086f95102951446e611ed1f2999fc4020ef711abf97f3a8f2c8af2b0f4436621f2cd3bd03cb83d5bc8d2461618338991e10573
7
+ data.tar.gz: be7eff5a1e22c58030d1f72842529f6e483adf405c2732320341c36b83584834aa2cd53d443911e2ad506fcefdd4eb770c57dc40de3f71fa9d715819052cd11f
@@ -330,13 +330,15 @@ CKEDITOR.plugins.add 'effective_menus',
330
330
  id: 'source',
331
331
  type: 'radio',
332
332
  label: 'Link Type',
333
- items: [['Page', 'Page'], ['URL', 'URL'], ['Route', 'Route'], ['Divider', 'Divider']]
333
+ items: [['Page', 'Page'], ['URL', 'URL'], ['Route', 'Route'], ['Divider', 'Divider'], ['Dropdown', 'Dropdown']]
334
334
  setup: (element) ->
335
335
  menuable_id = element.children('.menu-item').children("input[name$='[menuable_id]']").val() || ''
336
336
  special = element.children('.menu-item').children("input[name$='[special]']").val() || ''
337
337
  url = element.children('.menu-item').children("input[name$='[url]']").val() || ''
338
338
 
339
- if menuable_id.length > 0
339
+ if this.getDialog().effective_menu_item.hasClass('dropdown')
340
+ this.setValue('Dropdown')
341
+ else if menuable_id.length > 0
340
342
  this.setValue('Page')
341
343
  else if special == 'divider'
342
344
  this.setValue('Divider')
@@ -348,12 +350,18 @@ CKEDITOR.plugins.add 'effective_menus',
348
350
  this.setValue('Page')
349
351
 
350
352
  onChange: (event) ->
353
+ if this.getValue() != 'Dropdown'
354
+ radios = $('#' + this.getDialog().getContentElement('item', 'source').getElement().getId())
355
+ radios.find('input').prop('disabled', false)
356
+ radios.find("input[value='Dropdown']").prop('disabled', true)
357
+
351
358
  if this.getValue() == 'Page'
352
359
  this.getDialog().getContentElement('item', 'title').getElement().show()
353
360
  this.getDialog().getContentElement('item', 'menuable_id').getElement().show()
354
361
 
355
362
  this.getDialog().getContentElement('item', 'url').getElement().hide()
356
363
  this.getDialog().getContentElement('item', 'special').getElement().hide()
364
+ this.getDialog().getContentElement('item', 'dropdown').getElement().hide()
357
365
 
358
366
  if this.getValue() == 'URL'
359
367
  this.getDialog().getContentElement('item', 'title').getElement().show()
@@ -361,12 +369,23 @@ CKEDITOR.plugins.add 'effective_menus',
361
369
 
362
370
  this.getDialog().getContentElement('item', 'menuable_id').getElement().hide()
363
371
  this.getDialog().getContentElement('item', 'special').getElement().hide()
372
+ this.getDialog().getContentElement('item', 'dropdown').getElement().hide()
364
373
 
365
374
  if this.getValue() == 'Divider'
366
375
  this.getDialog().getContentElement('item', 'url').getElement().hide()
367
376
  this.getDialog().getContentElement('item', 'title').getElement().hide()
368
377
  this.getDialog().getContentElement('item', 'menuable_id').getElement().hide()
369
378
  this.getDialog().getContentElement('item', 'special').getElement().hide()
379
+ this.getDialog().getContentElement('item', 'dropdown').getElement().hide()
380
+
381
+ if this.getValue() == 'Dropdown'
382
+ this.getDialog().getContentElement('item', 'title').getElement().show()
383
+ this.getDialog().getContentElement('item', 'dropdown').getElement().show()
384
+ $('#' + this.getDialog().getContentElement('item', 'source').getElement().getId()).find('input').prop('disabled', true)
385
+
386
+ this.getDialog().getContentElement('item', 'special').getElement().hide()
387
+ this.getDialog().getContentElement('item', 'url').getElement().hide()
388
+ this.getDialog().getContentElement('item', 'menuable_id').getElement().hide()
370
389
 
371
390
  if this.getValue() == 'Route'
372
391
  this.getDialog().getContentElement('item', 'title').getElement().show()
@@ -374,32 +393,28 @@ CKEDITOR.plugins.add 'effective_menus',
374
393
 
375
394
  this.getDialog().getContentElement('item', 'menuable_id').getElement().hide()
376
395
  this.getDialog().getContentElement('item', 'url').getElement().hide()
396
+ this.getDialog().getContentElement('item', 'dropdown').getElement().hide()
377
397
  },
378
398
  {
379
399
  id: 'menuable_id',
380
400
  type: 'select',
381
401
  label: 'Page',
382
- items: (
383
- pages = []
384
- $.ajax
385
- url: '/admin/pages'
386
- dataType: 'json'
387
- async: false
388
- complete: (data) -> pages = data.responseJSON
389
- pages
390
- ),
402
+ items: ((CKEDITOR.config['effective_regions'] || {})['pages'] || [['', '']]),
391
403
  setup: (element) ->
392
404
  this.setValue(element.children('.menu-item').children("input[name$='[menuable_id]']").val())
393
405
  commit: (element) ->
394
- if this.getElement().isVisible()
406
+ if this.getDialog().getValueOf('item', 'source') == 'Page'
395
407
  element.children('.menu-item').children("input[name$='[menuable_id]']").val(this.getValue())
396
408
  element.children('.menu-item').children("input[name$='[menuable_type]']").val('Effective::Page')
409
+ else if this.getDialog().getValueOf('item', 'source') == 'Dropdown'
410
+ # Nothing
397
411
  else
398
412
  element.children('.menu-item').children("input[name$='[menuable_id]']").val('')
399
413
  element.children('.menu-item').children("input[name$='[menuable_type]']").val('')
400
414
  validate: ->
401
- if this.getElement().isVisible() && (this.getValue() || '').length == 0
402
- CKEDITOR.dialog.validate.notEmpty('please select a page').apply(this)
415
+ if this.getDialog().getValueOf('item', 'source') == 'Page' && (this.getValue() || '').length == 0
416
+ if this.getDialog().effective_menu_item.hasClass('dropdown') == false
417
+ CKEDITOR.dialog.validate.notEmpty('please select a page').apply(this)
403
418
  },
404
419
  {
405
420
  id: 'url',
@@ -408,12 +423,13 @@ CKEDITOR.plugins.add 'effective_menus',
408
423
  setup: (element) ->
409
424
  this.setValue(element.children('.menu-item').children("input[name$='[url]']").val())
410
425
  commit: (element) ->
411
- if this.getElement().isVisible() then value = this.getValue() else value = ''
426
+ if this.getDialog().getValueOf('item', 'source') == 'URL' then value = this.getValue() else value = ''
412
427
 
413
- element.children('.menu-item').children("input[name$='[url]']").val(value)
414
- element.children('a').attr('href', value || '#')
428
+ if this.getDialog().getValueOf('item', 'source') != 'Dropdown'
429
+ element.children('.menu-item').children("input[name$='[url]']").val(value)
430
+ element.children('a').attr('href', value || '#')
415
431
  validate: ->
416
- if this.getElement().isVisible() && (this.getValue() || '').length == 0
432
+ if this.getDialog().getValueOf('item', 'source') == 'URL' && (this.getValue() || '').length == 0
417
433
  CKEDITOR.dialog.validate.notEmpty('please enter a URL').apply(this)
418
434
  },
419
435
  {
@@ -426,8 +442,10 @@ CKEDITOR.plugins.add 'effective_menus',
426
442
  if this.getDialog().getValueOf('item', 'source') == 'Divider'
427
443
  element.children('.menu-item').children("input[name$='[special]']").val('divider')
428
444
  element.children('a').html('')
429
- else if this.getElement().isVisible()
445
+ else if this.getDialog().getValueOf('item', 'source') == 'Route'
430
446
  element.children('.menu-item').children("input[name$='[special]']").val(this.getValue())
447
+ else if this.getDialog().getValueOf('item', 'source') == 'Dropdown'
448
+ # Nothing
431
449
  else
432
450
  element.children('.menu-item').children("input[name$='[special]']").val('')
433
451
  # There is more stuff in the classes commit
@@ -435,9 +453,14 @@ CKEDITOR.plugins.add 'effective_menus',
435
453
  if this.getDialog().getValueOf('item', 'source') == 'Divider'
436
454
  if this.getDialog().effective_menu_item.hasClass('dropdown')
437
455
  CKEDITOR.dialog.validate.notEmpty('cannot convert existing dropdown menu to a Divider').apply(this)
438
- else if this.getElement().isVisible()
456
+ else if this.getDialog().getValueOf('item', 'source') == 'Route'
439
457
  if (this.getValue() || '').length == 0
440
458
  CKEDITOR.dialog.validate.notEmpty('please enter a route').apply(this)
459
+ },
460
+ {
461
+ id: 'dropdown',
462
+ type: 'html',
463
+ html: 'Dropdown menu items cannot also be links.<br><br>To change this dropdown back to a regular menu item,<br>please click Cancel and then use the drag & drop<br>functionality to remove all its child menu items.'
441
464
  }
442
465
  ] # /tab1 elements
443
466
  },
@@ -455,7 +478,9 @@ CKEDITOR.plugins.add 'effective_menus',
455
478
  onChange: (event) ->
456
479
  if this.getValue() == true
457
480
  this.getDialog().setValueOf('permissions', 'signed_in', false)
458
- this.getDialog().setValueOf('permissions', 'roles_mask', '')
481
+
482
+ for role, index in ((CKEDITOR.config['effective_regions'] || {})['roles'] || [])
483
+ this.getDialog().setValueOf('permissions', "role_#{role[1]}", false)
459
484
  },
460
485
  {
461
486
  id: 'signed_in',
@@ -467,30 +492,50 @@ CKEDITOR.plugins.add 'effective_menus',
467
492
  onChange: (event) ->
468
493
  if this.getValue() == true
469
494
  this.getDialog().setValueOf('permissions', 'signed_out', false)
470
- },
495
+ }
471
496
  {
472
- id: 'roles_mask',
473
- type: 'text',
474
- label: 'Roles Mask',
475
- setup: (element) ->
476
- value = parseInt(element.children('.menu-item').children("input[name$='[roles_mask]']").val(), 10)
477
- if value > 0 then this.setValue(value) else this.setValue('')
497
+ id: 'roles',
498
+ type: 'vbox',
499
+ width: '100%',
500
+ children:
501
+ [{type: 'html', html: '<p>Only visible when signed in as a user with one or more<br>of the following website roles:</p>'}].concat(
502
+ for role, index in ((CKEDITOR.config['effective_regions'] || {})['roles'] || [])
503
+ bit_mask = Math.pow(2, index)
504
+ # role == [description, title, 'disabled' or null] We're not using description
505
+ {
506
+ id: "role_#{role[1]}",
507
+ type: 'checkbox',
508
+ label: "#{role[1]}",
509
+ className: "role_#{bit_mask}_#{role[2]}_box"
510
+ setup: (element) ->
511
+ this.disable() if (this.className.split('_')[2] == 'disabled')
512
+
513
+ roles_mask = parseInt(element.children('.menu-item').children("input[name$='[roles_mask]']").val(), 10) || 0
514
+ roles_mask = 0 if roles_mask == -1
515
+ bit_mask = parseInt(this.className.split('_')[1], 10) || 0
516
+
517
+ this.setValue((bit_mask & roles_mask) != 0)
518
+ onClick: (event) ->
519
+ if this.getValue() == true # Ensure Only visible when signed in is checked too if we have roles
520
+ this.getDialog().setValueOf('permissions', 'signed_in', true)
521
+ this.getDialog().setValueOf('permissions', 'signed_out', false)
522
+ }
523
+ )
478
524
  commit: (element) ->
479
- if ('' + this.getValue()).length > 0
480
- element.children('.menu-item').children("input[name$='[roles_mask]']").val(this.getValue())
525
+ roles_mask = 0
526
+
527
+ for role, index in ((CKEDITOR.config['effective_regions'] || {})['roles'] || [])
528
+ if this.getDialog().getValueOf('permissions', "role_#{role[1]}") == true
529
+ roles_mask += Math.pow(2, index)
530
+
531
+ if roles_mask > 0
532
+ element.children('.menu-item').children("input[name$='[roles_mask]']").val(roles_mask)
481
533
  else if this.getDialog().getValueOf('permissions', 'signed_in') == true
482
534
  element.children('.menu-item').children("input[name$='[roles_mask]']").val(0)
483
535
  else if this.getDialog().getValueOf('permissions', 'signed_out') == true
484
536
  element.children('.menu-item').children("input[name$='[roles_mask]']").val(-1)
485
537
  else
486
538
  element.children('.menu-item').children("input[name$='[roles_mask]']").val('')
487
- onKeyup: (event) ->
488
- if ('' + this.getValue()).length > 0
489
- this.getDialog().setValueOf('permissions', 'signed_in', true)
490
- this.getDialog().setValueOf('permissions', 'signed_out', false)
491
- validate: ->
492
- if ('' + this.getValue()).length > 0
493
- CKEDITOR.dialog.validate.integer('roles_mask must be an integer').apply(this)
494
539
  }
495
540
  ]
496
541
  },
@@ -537,11 +582,11 @@ CKEDITOR.plugins.add 'effective_menus',
537
582
  onShow: -> this.setupContent(this.effective_menu_item) if this.effective_menu_item
538
583
 
539
584
  onOk: ->
540
- this.commitContent(this.effective_menu_item)
541
- this.effective_menu_item.removeClass('new-item') if this.effective_menu_item.hasClass('new-item')
542
- this.effective_menu_item = undefined
585
+ if this.effective_menu_item
586
+ this.commitContent(this.effective_menu_item)
587
+ this.effective_menu_item.removeClass('new-item') if this.effective_menu_item.hasClass('new-item')
543
588
 
544
589
  onCancel: ->
545
- this.effective_menu_item.remove() if this.effective_menu_item.hasClass('new-item')
546
- this.effective_menu_item = undefined
590
+ if this.effective_menu_item && this.effective_menu_item.hasClass('new-item')
591
+ this.effective_menu_item.remove()
547
592
  }
@@ -108,7 +108,7 @@ Regions = {
108
108
  }
109
109
 
110
110
  Snippets = {
111
- all: -> CKEDITOR.config['effective_regions']['snippets']
111
+ all: -> ((CKEDITOR.config['effective_regions'] || {})['snippets'] || {})
112
112
 
113
113
  build: (editor, name, values) ->
114
114
  snippet = {}
@@ -168,7 +168,7 @@ Snippets = {
168
168
  }
169
169
 
170
170
  Templates = {
171
- all: -> CKEDITOR.config['effective_regions']['templates']
171
+ all: -> ((CKEDITOR.config['effective_regions'] || {})['templates'] || {})
172
172
  build: (definition) -> definition
173
173
  }
174
174
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveCkeditor
2
- VERSION = '1.5.0'.freeze
2
+ VERSION = '1.5.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_ckeditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-17 00:00:00.000000000 Z
11
+ date: 2015-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails